From patchwork Wed Oct 14 07:22:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: yang_y_yi X-Patchwork-Id: 1381836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=163.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=b20EBBzt; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CB3pG1RRyz9sVH for ; Wed, 14 Oct 2020 18:24:53 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id B4B542E24C; Wed, 14 Oct 2020 07:24:50 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CmjoLbXDb1Y4; Wed, 14 Oct 2020 07:24:48 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 988652E23A; Wed, 14 Oct 2020 07:24:47 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id CB515C07FF; Wed, 14 Oct 2020 07:24:47 +0000 (UTC) X-Original-To: ovs-dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 3C63FC0051 for ; Wed, 14 Oct 2020 07:24:45 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 36C9E87BEC for ; Wed, 14 Oct 2020 07:24:45 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id EbfG3mpEOKpf for ; Wed, 14 Oct 2020 07:24:44 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by hemlock.osuosl.org (Postfix) with ESMTPS id D490F87BE0 for ; Wed, 14 Oct 2020 07:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=zKLJW tgL8UnHG6dNrqFYfuDnlsPC1ceu1YhnEE9Y9BU=; b=b20EBBztS19nIxQbeMxXd UIItujT4nLo0yVdY4JUQ4xJulmdqUyRi8Daq5KNAjyKvLV9eHEtIIrNZ9HbJGSdv nBaNC7m8YiUW4FBTDdPgdRnIBeRQsbklm/t/I002dZ3Rg1ag2W83899ZyVITJ3jv AthPVQcr8k91jHf+/qseWc= Received: from yangyi0100.home.langchao.com (unknown [111.207.123.58]) by smtp4 (Coremail) with SMTP id HNxpCgCnXe5Ip4ZfSLvFTw--.7031S2; Wed, 14 Oct 2020 15:22:49 +0800 (CST) From: yang_y_yi@163.com To: ovs-dev@openvswitch.org Date: Wed, 14 Oct 2020 15:22:48 +0800 Message-Id: <20201014072248.374384-1-yang_y_yi@163.com> X-Mailer: git-send-email 2.19.2.windows.1 MIME-Version: 1.0 X-CM-TRANSID: HNxpCgCnXe5Ip4ZfSLvFTw--.7031S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxWFW7Wr4fJrykAr45tryrJFb_yoW5GrW3pa 13Kr17ArZ8Jw4xKFy0qw4Iq3W5KrWkKrW8KrZ2vF1fur45Z3s2q348Kay0vFy3K3s2yw1r Zr4qvFW5W3W8CFJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07UfuciUUUUU= X-Originating-IP: [111.207.123.58] X-CM-SenderInfo: 51dqwsp1b1xqqrwthudrp/xtbB0gq9i1UMZH4OHAAAs- Cc: olivier.matz@6wind.com, i.maximets@ovn.org, yang_y_yi@163.com, fbl@sysclose.org Subject: [ovs-dev] [PATCH] netdev-dpdk: fix incorrect shinfo initialization X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Yi Yang shinfo is used to store reference counter and free callback of an external buffer, but it is stored in mbuf if the mbuf has tailroom for it. This is wrong because the mbuf (and its data) can be freed before the external buffer, for example: pkt2 = rte_pktmbuf_alloc(mp); rte_pktmbuf_attach(pkt2, pkt); rte_pktmbuf_free(pkt); After this, pkt is freed, but it still contains shinfo, which is referenced by pkt2. Fix this by always storing shinfo at the tail of external buffer. Fixes: 29cf9c1b3b9c ("userspace: Add TCP Segmentation Offload support") Co-authored-by: Olivier Matz Signed-off-by: Olivier Matz Signed-off-by: Yi Yang Acked-by: Flavio Leitner --- lib/netdev-dpdk.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 0b830be..c7f9326 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -2654,12 +2654,8 @@ dpdk_pktmbuf_attach_extbuf(struct rte_mbuf *pkt, uint32_t data_len) uint16_t buf_len; void *buf; - if (rte_pktmbuf_tailroom(pkt) >= sizeof *shinfo) { - shinfo = rte_pktmbuf_mtod(pkt, struct rte_mbuf_ext_shared_info *); - } else { - total_len += sizeof *shinfo + sizeof(uintptr_t); - total_len = RTE_ALIGN_CEIL(total_len, sizeof(uintptr_t)); - } + total_len += sizeof *shinfo + sizeof(uintptr_t); + total_len = RTE_ALIGN_CEIL(total_len, sizeof(uintptr_t)); if (OVS_UNLIKELY(total_len > UINT16_MAX)) { VLOG_ERR("Can't copy packet: too big %u", total_len); @@ -2674,20 +2670,14 @@ dpdk_pktmbuf_attach_extbuf(struct rte_mbuf *pkt, uint32_t data_len) } /* Initialize shinfo. */ - if (shinfo) { - shinfo->free_cb = netdev_dpdk_extbuf_free; - shinfo->fcb_opaque = buf; - rte_mbuf_ext_refcnt_set(shinfo, 1); - } else { - shinfo = rte_pktmbuf_ext_shinfo_init_helper(buf, &buf_len, - netdev_dpdk_extbuf_free, - buf); - if (OVS_UNLIKELY(shinfo == NULL)) { - rte_free(buf); - VLOG_ERR("Failed to initialize shared info for mbuf while " - "attempting to attach an external buffer."); - return NULL; - } + shinfo = rte_pktmbuf_ext_shinfo_init_helper(buf, &buf_len, + netdev_dpdk_extbuf_free, + buf); + if (OVS_UNLIKELY(shinfo == NULL)) { + rte_free(buf); + VLOG_ERR("Failed to initialize shared info for mbuf while " + "attempting to attach an external buffer."); + return NULL; } rte_pktmbuf_attach_extbuf(pkt, buf, rte_malloc_virt2iova(buf), buf_len,