From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id E5FBDA04DB for ; Thu, 10 Dec 2020 01:27:38 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D93A5C926; Thu, 10 Dec 2020 01:27:37 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by dpdk.org (Postfix) with ESMTP id 671E0C926 for ; Thu, 10 Dec 2020 01:27:35 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1004) id C55D420B717A; Wed, 9 Dec 2020 16:27:34 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C55D420B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxonhyperv.com; s=default; t=1607560054; bh=oxu3Hq2a3RctY0GuW9QuhaWSjt+irHUuSHSFWDQBUPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jomKIeQuUbs94RbgzIbKVUvUBp3bH0wvaiM3uHW0qd2zz+6I35wLfLFfeeYSXgrZj DZr65FOYlBG0smbfsuWukDiVo96+b7W/+ECLCYsnDp+Rov0gE+ziNkfyfVPMZu0s5x X6VOajxb8TBQ/mJeV2CLxJHTNd9Oz9b4aeJcsp2s= From: Long Li To: stable@dpdk.org Cc: Long Li Date: Wed, 9 Dec 2020 16:27:17 -0800 Message-Id: <1607560037-30478-2-git-send-email-longli@linuxonhyperv.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1607560037-30478-1-git-send-email-longli@linuxonhyperv.com> References: <1607560037-30478-1-git-send-email-longli@linuxonhyperv.com> Subject: [dpdk-stable] [PATCH 19.11 2/2] net/netvsc: control use of external mbuf on Rx X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org Sender: "stable" From: Long Li [ upstream commit 096b31fc0d8c989cc455c35f4d1def24a4ed6dee ] When receiving packets, netvsp puts data in a buffer mapped through UIO. Depending on packet size, netvsc may attach the buffer as an external mbuf. This is not a problem if this mbuf is consumed in the application, and the application can correctly read data out of an external mbuf. However, there are two problems with data in an external mbuf. 1. Due to the limitation of the kernel UIO implementation, physical address of this external buffer is not exposed to the user-mode. If this mbuf is passed to another driver, the other driver is unable to map this buffer to iova. 2. Some DPDK applications are not aware of external mbuf, and may bug when they receive an mbuf with external buffer attached. Introduce a driver parameter "rx_extmbuf_enable" to control if netvsc should use external mbuf for receiving packets. The default value is 0. (netvsc doesn't use external mbuf, it always allocates mbuf and copy data to mbuf) A non-zero value tells netvsc to attach external buffers to mbuf on receiving packets, thus avoid copying memory. Signed-off-by: Long Li --- doc/guides/nics/netvsc.rst | 8 ++++++++ drivers/net/netvsc/hn_ethdev.c | 10 +++++++++- drivers/net/netvsc/hn_rxtx.c | 2 +- drivers/net/netvsc/hn_var.h | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/doc/guides/nics/netvsc.rst b/doc/guides/nics/netvsc.rst index 5a68ffa8a3..19f9940fe6 100644 --- a/doc/guides/nics/netvsc.rst +++ b/doc/guides/nics/netvsc.rst @@ -133,3 +133,11 @@ The user can specify below argument in devargs. set larger than the MTU, then all packets smaller than the chunk size of the VMBus send buffer will be copied; larger packets always have to go as a single direct request. The default value is 512 (bytes). + +#. ``rx_extmbuf_enable``: + The rx_extmbuf_enable is used to control if netvsc should use external + mbuf for receiving packets. The default value is 0. (netvsc doesn't use + external mbuf, it always allocates mbuf and copy received data to mbuf) + A non-zero value tells netvsc to attach external buffers to mbuf on + receiving packets, thus avoid copying memory. Use of external buffers + requires the application is able to read data from external mbuf. diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c index e2f5adc498..596bec4860 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -50,6 +50,7 @@ int hn_logtype_driver; #define NETVSC_ARG_LATENCY "latency" #define NETVSC_ARG_RXBREAK "rx_copybreak" #define NETVSC_ARG_TXBREAK "tx_copybreak" +#define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable" struct hn_xstats_name_off { char name[RTE_ETH_XSTATS_NAME_SIZE]; @@ -168,6 +169,10 @@ static int hn_set_parameter(const char *key, const char *value, void *opaque) hv->tx_copybreak = v; PMD_DRV_LOG(DEBUG, "tx copy break set to %u", hv->tx_copybreak); + } else if (!strcmp(key, NETVSC_ARG_RX_EXTMBUF_ENABLE)) { + hv->rx_extmbuf_enable = v; + PMD_DRV_LOG(DEBUG, "rx extmbuf enable set to %u", + hv->rx_extmbuf_enable); } return 0; @@ -182,6 +187,7 @@ static int hn_parse_args(const struct rte_eth_dev *dev) NETVSC_ARG_LATENCY, NETVSC_ARG_RXBREAK, NETVSC_ARG_TXBREAK, + NETVSC_ARG_RX_EXTMBUF_ENABLE, NULL }; struct rte_kvargs *kvlist; @@ -970,6 +976,7 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) hv->latency = HN_CHAN_LATENCY_NS; hv->rx_copybreak = HN_RXCOPY_THRESHOLD; hv->tx_copybreak = HN_TXCOPY_THRESHOLD; + hv->rx_extmbuf_enable = HN_RX_EXTMBUF_ENABLE; hv->max_queues = 1; rte_spinlock_init(&hv->vf_lock); hv->vf_port = HN_INVALID_PORT; @@ -1141,4 +1148,5 @@ RTE_INIT(hn_init_log) RTE_PMD_REGISTER_PARAM_STRING(net_netvsc, NETVSC_ARG_LATENCY "= " NETVSC_ARG_RXBREAK "= " - NETVSC_ARG_TXBREAK "="); + NETVSC_ARG_TXBREAK "= " + NETVSC_ARG_RX_EXTMBUF_ENABLE "=<0|1>"); diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c index 1cbb2ccee5..e1cf15c090 100644 --- a/drivers/net/netvsc/hn_rxtx.c +++ b/drivers/net/netvsc/hn_rxtx.c @@ -538,7 +538,7 @@ static void hn_rxpkt(struct hn_rx_queue *rxq, struct hn_rx_bufinfo *rxb, * For large packets, avoid copy if possible but need to keep * some space available in receive area for later packets. */ - if (dlen > hv->rx_copybreak && + if (hv->rx_extmbuf_enable && dlen > hv->rx_copybreak && (uint32_t)rte_atomic32_read(&rxq->rxbuf_outstanding) < hv->rxbuf_section_cnt / 2) { struct rte_mbuf_ext_shared_info *shinfo; diff --git a/drivers/net/netvsc/hn_var.h b/drivers/net/netvsc/hn_var.h index 50ca1e56ca..61593827af 100644 --- a/drivers/net/netvsc/hn_var.h +++ b/drivers/net/netvsc/hn_var.h @@ -26,6 +26,8 @@ #define HN_TXCOPY_THRESHOLD 512 #define HN_RXCOPY_THRESHOLD 256 +#define HN_RX_EXTMBUF_ENABLE 0 + /* Buffers need to be aligned */ #ifndef PAGE_SIZE #define PAGE_SIZE 4096 @@ -119,6 +121,7 @@ struct hn_data { struct rte_mem_resource *rxbuf_res; /* UIO resource for Rx */ uint32_t rxbuf_section_cnt; /* # of Rx sections */ uint32_t rx_copybreak; + uint32_t rx_extmbuf_enable; uint16_t max_queues; /* Max available queues */ uint16_t num_queues; uint64_t rss_offloads; -- 2.27.0