From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id E7C61A0547; Thu, 9 Sep 2021 16:46:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C878840041; Thu, 9 Sep 2021 16:46:33 +0200 (CEST) Received: from mail-oi1-f226.google.com (mail-oi1-f226.google.com [209.85.167.226]) by mails.dpdk.org (Postfix) with ESMTP id 2F8964003E for ; Thu, 9 Sep 2021 16:46:31 +0200 (CEST) Received: by mail-oi1-f226.google.com with SMTP id bi4so2767842oib.9 for ; Thu, 09 Sep 2021 07:46:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:date:subject:message-id; bh=jyaLEZymC1uHLqLg1KuV4CVGP7i1Uc8IsyITIjQaXIk=; b=yk9BJ+N1Xv/8iTzcz8gVe0QabBnv0gTM1xPF3+xG/FNLPr8Jf2d8IRtuesWxmctqm/ HUtB7LO7ACHN68CPK6hcbEqQ3q+2+ICE01LQ+apMq1uD4KJu8cfJAcw9pUxcP6NR6XAw NHLXDiJOojg6vPk6yk7/iuOFbQEM18f11hGcjKsoNJOC493b7ihyfqgZQPV1XiHKvU5m 23/RGubI08t4poqTWHIep2+fUikxJZVVY5P/+U+TbVFn8spRgoBCLIiwtpIq5Kog3P1y 0ooEjErYE0+Yej6nNURODa8A7v30gip0GzkiLL7oplNO/7zQzQfaQtpDB49LxRKCjAN/ lc5Q== X-Gm-Message-State: AOAM532tvdVa+nmpyMXqhK8YJBBYK0eNVSJ3mMRqwG/eDkAO55voTrux 3Cy5ZmZp+GoKkh/+59u69MeZjOge9rILXapOC8w8snJ7E0Mrug== X-Google-Smtp-Source: ABdhPJwNIe2JPnDTAMAI+4WhsARfJyw/8CNuSsYpqftF04MA3sXJnFtPR/LVlTFv5lyQGkJZDux9ECjHeXD9 X-Received: by 2002:aca:3051:: with SMTP id w78mr129646oiw.159.1631198791298; Thu, 09 Sep 2021 07:46:31 -0700 (PDT) Received: from optima.cs.arizona.edu (optima.cs.arizona.edu. [192.12.69.5]) by smtp-relay.gmail.com with ESMTPS id c23sm496850otl.9.2021.09.09.07.46.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Sep 2021 07:46:31 -0700 (PDT) X-Relaying-Domain: cs.arizona.edu Received: from cs.arizona.edu (lectura.cs.arizona.edu [192.12.69.186]) by optima.cs.arizona.edu (8.14.4/8.14.4/Debian-2ubuntu2.1) with ESMTP id 189EkUML008403 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 9 Sep 2021 07:46:30 -0700 Received: from localhost (cs.arizona.edu [local]) by cs.arizona.edu (OpenSMTPD) with ESMTPA id 0b990f5d for ; Thu, 9 Sep 2021 14:46:21 +0000 (UTC) From: Junxiao Shi To: dev@dpdk.org Date: Thu, 9 Sep 2021 14:42:06 +0000 Message-ID: <973f32e49849ad68@cs.arizona.edu> Subject: [dpdk-dev] [PATCH] net/memif: fix chained mbuf determination X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 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" Previously, TX functions call rte_pktmbuf_is_contiguous to determine whether an mbuf is chained. However, rte_pktmbuf_is_contiguous is designed to work on the first mbuf of a packet only. In case a packet contains three or more segment mbufs in a chain, it may cause truncated packets or rte_mbuf_sanity_check panics. This patch updates TX functions to determine chained mbufs using mbuf_head->nb_segs field, which works in all cases. Moreover, it maintains that the second cacheline is only accessed when chained mbuf is actually present. Signed-off-by: Junxiao Shi --- drivers/net/memif/rte_eth_memif.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/memif/rte_eth_memif.c b/drivers/net/memif/rte_eth_memif.c index de6becd45e..fd9e877c3d 100644 --- a/drivers/net/memif/rte_eth_memif.c +++ b/drivers/net/memif/rte_eth_memif.c @@ -199,6 +199,7 @@ memif_dev_info(struct rte_eth_dev *dev __rte_unused, struct rte_eth_dev_info *de dev_info->max_rx_queues = ETH_MEMIF_MAX_NUM_Q_PAIRS; dev_info->max_tx_queues = ETH_MEMIF_MAX_NUM_Q_PAIRS; dev_info->min_rx_bufsize = 0; + dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS; return 0; } @@ -567,7 +568,7 @@ eth_memif_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) rte_eth_devices[mq->in_port].process_private; memif_ring_t *ring = memif_get_ring_from_queue(proc_private, mq); uint16_t slot, saved_slot, n_free, ring_size, mask, n_tx_pkts = 0; - uint16_t src_len, src_off, dst_len, dst_off, cp_len; + uint16_t src_len, src_off, dst_len, dst_off, cp_len, nb_segs; memif_ring_type_t type = mq->type; memif_desc_t *d0; struct rte_mbuf *mbuf; @@ -615,6 +616,7 @@ eth_memif_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) while (n_tx_pkts < nb_pkts && n_free) { mbuf_head = *bufs++; + nb_segs = mbuf_head->nb_segs; mbuf = mbuf_head; saved_slot = slot; @@ -659,7 +661,7 @@ eth_memif_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) d0->length = dst_off; } - if (rte_pktmbuf_is_contiguous(mbuf) == 0) { + if (--nb_segs > 0) { mbuf = mbuf->next; goto next_in_chain; } @@ -696,6 +698,7 @@ memif_tx_one_zc(struct pmd_process_private *proc_private, struct memif_queue *mq uint16_t slot, uint16_t n_free) { memif_desc_t *d0; + uint16_t nb_segs = mbuf->nb_segs; int used_slots = 1; next_in_chain: @@ -716,7 +719,7 @@ memif_tx_one_zc(struct pmd_process_private *proc_private, struct memif_queue *mq d0->flags = 0; /* check if buffer is chained */ - if (rte_pktmbuf_is_contiguous(mbuf) == 0) { + if (--nb_segs > 0) { if (n_free < 2) return 0; /* mark buffer as chained */ -- 2.17.1