From patchwork Thu Jul 30 12:09:00 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: 75037 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 319C6A052B; Thu, 30 Jul 2020 14:09:25 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9FFC61C00D; Thu, 30 Jul 2020 14:09:09 +0200 (CEST) Received: from mail-m974.mail.163.com (mail-m974.mail.163.com [123.126.97.4]) by dpdk.org (Postfix) with ESMTP id 7FFD910A3 for ; Thu, 30 Jul 2020 14:09:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=lFDu0 tBdjS+Pgn1WClXzcYpD7IRxZ1x0v3sOwg3KcrI=; b=YWRNUYZJRlvWIshMTsyfq VrflWZUCmlLD0ORjK6CiPg46Ukckx9cYyoQbUNj943W5e927X0NIDtkY+IMmVaZy lMrVlwERYnYznZ4O0MPEtXUv4bi7iQ6Pt6cj8TiO88FRQYCrfTBaAZbvcprZYPaP 8obQxOGmomfljEgM+uif3U= Received: from yangyi0100.home.langchao.com (unknown [61.48.210.155]) by smtp4 (Coremail) with SMTP id HNxpCgBXekNcuCJfZo1vIA--.3698S5; Thu, 30 Jul 2020 20:09:02 +0800 (CST) From: yang_y_yi@163.com To: dev@dpdk.org Cc: jiayu.hu@intel.com, thomas@monjalon.net, yangyi01@inspur.com, yang_y_yi@163.com Date: Thu, 30 Jul 2020 20:09:00 +0800 Message-Id: <20200730120900.108232-4-yang_y_yi@163.com> X-Mailer: git-send-email 2.19.2.windows.1 In-Reply-To: <20200730120900.108232-1-yang_y_yi@163.com> References: <20200730120900.108232-1-yang_y_yi@163.com> MIME-Version: 1.0 X-CM-TRANSID: HNxpCgBXekNcuCJfZo1vIA--.3698S5 X-Coremail-Antispam: 1Uf129KBjvJXoW7ZrWfXF1DZF1Utw4UArykAFb_yoW8Ar45pF 43Gry5Ar1rJr4xKrsxCr4fK3Z3Kayvk3W7CrZa9w1F9r4xX34xXFykKFWrur13Kr97Ar43 XF40qF1UK3WUuFDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jBeHgUUUUU= X-Originating-IP: [61.48.210.155] X-CM-SenderInfo: 51dqwsp1b1xqqrwthudrp/1tbiqBBxi1c7RBg70AAAsZ Subject: [dpdk-dev] [PATCH V1 3/3] vhost: use new free_cb interface to fix mbuf free issue 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" From: Yi Yang New free_cb interface can help fix original external mbuf free issue in GSO case, it still can be compatible with normal non-GSO case. dpdkvhostuser port can work both in GSO case and in non-GSO case by this fix. Signed-off-by: Yi Yang --- lib/librte_vhost/virtio_net.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index e663fd4..3b69cbb 100644 --- a/lib/librte_vhost/virtio_net.c +++ b/lib/librte_vhost/virtio_net.c @@ -2136,10 +2136,20 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, return NULL; } +struct shinfo_arg { + void *buf; + struct rte_mbuf *mbuf; +}; + static void -virtio_dev_extbuf_free(struct rte_mbuf * caller_m __rte_unused, void *opaque) +virtio_dev_extbuf_free(struct rte_mbuf *caller_m, void *opaque) { - rte_free(opaque); + struct shinfo_arg *arg = (struct shinfo_arg *)opaque; + + rte_free(arg->buf); + if (caller_m != arg->mbuf) + rte_pktmbuf_free(arg->mbuf); + rte_free(arg); } static int @@ -2172,8 +2182,14 @@ uint16_t rte_vhost_poll_enqueue_completed(int vid, uint16_t queue_id, /* Initialize shinfo */ if (shinfo) { + struct shinfo_arg *arg = (struct shinfo_arg *) + rte_malloc(NULL, sizeof(struct shinfo_arg), + RTE_CACHE_LINE_SIZE); + + arg->buf = buf; + arg->mbuf = pkt; shinfo->free_cb = virtio_dev_extbuf_free; - shinfo->fcb_opaque = buf; + shinfo->fcb_opaque = arg; rte_mbuf_ext_refcnt_set(shinfo, 1); } else { shinfo = rte_pktmbuf_ext_shinfo_init_helper(buf, &buf_len,