From patchwork Tue Nov 20 10:26:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lam, Tiago" X-Patchwork-Id: 48200 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 14BA72BD5; Tue, 20 Nov 2018 11:26:50 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id C08AD1D7 for ; Tue, 20 Nov 2018 11:26:47 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 02:26:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="90712025" Received: from silpixa00399125.ir.intel.com ([10.237.223.34]) by orsmga007.jf.intel.com with ESMTP; 20 Nov 2018 02:26:44 -0800 From: Tiago Lam To: dev@dpdk.org Cc: ferruh.yigit@intel.com, linville@tuxdriver.com, Tiago Lam Date: Tue, 20 Nov 2018 10:26:29 +0000 Message-Id: <1542709592-215007-1-git-send-email-tiago.lam@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542707697-175836-1-git-send-email-tiago.lam@intel.com> References: <1542707697-175836-1-git-send-email-tiago.lam@intel.com> Subject: [dpdk-dev] [PATCH v2 1/3] net/af_packet: set_mtu() decrements sockaddr twice 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" When setting the MTU, eth_dev_mtu_set() is called to validate the provided MTU. As part of that, it calculates the useful area to store data and compares it against the MTU, to guarantee that there's enough space to store the data. It calculates that as: "tp_frame_size - TPACKET2_HDRLEN - sizeof(struct sockaddr_ll)" However, the TPACKET2_HDRLEN macro already increaments sizeof(struct sockaddr_ll) internally, meaning the useuful area of data above will have sizeof(struct sockaddr_ll) decremented twice. Instead, the useful area of data should be calculated as: "tp_frame_size - TPACKET2_HDRLEN" This makes sure that there's enough useful area to fit the provided MTU after excluding tpacket2_hdr and sockaddr_ll. Fixes: cc68ac4 ("net/af_packet: support MTU change") Signed-off-by: Tiago Lam Reviewed-by: Ferruh Yigit --- drivers/net/af_packet/rte_eth_af_packet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 95a98c6..264cfc0 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -433,8 +433,7 @@ eth_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu) int ret; int s; unsigned int data_size = internals->req.tp_frame_size - - TPACKET2_HDRLEN - - sizeof(struct sockaddr_ll); + TPACKET2_HDRLEN; if (mtu > data_size) return -EINVAL; From patchwork Tue Nov 20 10:26:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lam, Tiago" X-Patchwork-Id: 48201 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 4FE1D4F9A; Tue, 20 Nov 2018 11:26:52 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 6E46C1D7 for ; Tue, 20 Nov 2018 11:26:48 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 02:26:47 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="90712031" Received: from silpixa00399125.ir.intel.com ([10.237.223.34]) by orsmga007.jf.intel.com with ESMTP; 20 Nov 2018 02:26:46 -0800 From: Tiago Lam To: dev@dpdk.org Cc: ferruh.yigit@intel.com, linville@tuxdriver.com, Tiago Lam Date: Tue, 20 Nov 2018 10:26:30 +0000 Message-Id: <1542709592-215007-2-git-send-email-tiago.lam@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542709592-215007-1-git-send-email-tiago.lam@intel.com> References: <1542707697-175836-1-git-send-email-tiago.lam@intel.com> <1542709592-215007-1-git-send-email-tiago.lam@intel.com> Subject: [dpdk-dev] [PATCH v2 2/3] net/af_packet: move parse and validation of iface 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" Instead of re-iterating through kvlist just to parse the ETH_AF_PACKET_IFACE_ARG argument in rte_pmd_init_internals(), we now use the already existing iteration in rte_eth_from_packet() to parse and validate the ETH_AF_PACKET_IFACE_ARG argument. This will be useful for a later commit, which needs to access the interface name to get the underlying configured MTU. Signed-off-by: Tiago Lam --- v2: Fix checkpatches.sh and check-git-log.sh warnings. --- drivers/net/af_packet/rte_eth_af_packet.c | 77 ++++++++++++++++--------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 264cfc0..8d749a2 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -540,15 +540,12 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, unsigned int qdisc_bypass, struct pmd_internals **internals, struct rte_eth_dev **eth_dev, - struct rte_kvargs *kvlist) + const char *ifname) { const char *name = rte_vdev_device_name(dev); const unsigned int numa_node = dev->device.numa_node; struct rte_eth_dev_data *data = NULL; - struct rte_kvargs_pair *pair = NULL; struct ifreq ifr; - size_t ifnamelen; - unsigned k_idx; struct sockaddr_ll sockaddr; struct tpacket_req *req; struct pkt_rx_queue *rx_queue; @@ -560,18 +557,6 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, int fanout_arg; #endif - for (k_idx = 0; k_idx < kvlist->count; k_idx++) { - pair = &kvlist->pairs[k_idx]; - if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL) - break; - } - if (pair == NULL) { - PMD_LOG(ERR, - "%s: no interface specified for AF_PACKET ethdev", - name); - return -1; - } - PMD_LOG(INFO, "%s: creating AF_PACKET-backed ethdev on numa socket %u", name, numa_node); @@ -593,23 +578,14 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, req->tp_frame_size = framesize; req->tp_frame_nr = framecnt; - ifnamelen = strlen(pair->value); - if (ifnamelen < sizeof(ifr.ifr_name)) { - memcpy(ifr.ifr_name, pair->value, ifnamelen); - ifr.ifr_name[ifnamelen] = '\0'; - } else { - PMD_LOG(ERR, - "%s: I/F name too long (%s)", - name, pair->value); - return -1; - } + memcpy(ifr.ifr_name, ifname, strlen(ifname)); if (ioctl(sockfd, SIOCGIFINDEX, &ifr) == -1) { PMD_LOG(ERR, "%s: ioctl failed (SIOCGIFINDEX)", name); return -1; } - (*internals)->if_name = strdup(pair->value); + (*internals)->if_name = strdup(ifname); if ((*internals)->if_name == NULL) return -1; (*internals)->if_index = ifr.ifr_ifindex; @@ -651,7 +627,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_VERSION on AF_PACKET socket for %s", - name, pair->value); + name, ifname); goto error; } @@ -661,7 +637,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_LOSS on AF_PACKET socket for %s", - name, pair->value); + name, ifname); goto error; } @@ -671,7 +647,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_QDISC_BYPASS on AF_PACKET socket for %s", - name, pair->value); + name, ifname); goto error; } #else @@ -682,7 +658,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_RX_RING on AF_PACKET socket for %s", - name, pair->value); + name, ifname); goto error; } @@ -690,7 +666,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_TX_RING on AF_PACKET " - "socket for %s", name, pair->value); + "socket for %s", name, ifname); goto error; } @@ -703,7 +679,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rx_queue->map == MAP_FAILED) { PMD_LOG(ERR, "%s: call to mmap failed on AF_PACKET socket for %s", - name, pair->value); + name, ifname); goto error; } @@ -740,7 +716,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not bind AF_PACKET socket to %s", - name, pair->value); + name, ifname); goto error; } @@ -750,7 +726,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, if (rc == -1) { PMD_LOG(ERR, "%s: could not set PACKET_FANOUT on AF_PACKET socket " - "for %s", name, pair->value); + "for %s", name, ifname); goto error; } #endif @@ -816,6 +792,9 @@ rte_eth_from_packet(struct rte_vdev_device *dev, unsigned int framecount = DFLT_FRAME_COUNT; unsigned int qpairs = 1; unsigned int qdisc_bypass = 1; + struct ifreq ifr; + char *ifname = NULL; + size_t ifnamelen; /* do some parameter checking */ if (*sockfd < 0) @@ -877,6 +856,32 @@ rte_eth_from_packet(struct rte_vdev_device *dev, } continue; } + if (strstr(pair->key, ETH_AF_PACKET_IFACE_ARG) != NULL) { + ifname = pair->value; + if (strlen(ifname) == 0) { + RTE_LOG(ERR, PMD, + "%s: invalid iface value\n", + name); + return -1; + } + + continue; + } + } + + if (ifname == NULL) { + RTE_LOG(ERR, PMD, + "%s: no interface specified for AF_PACKET ethdev\n", + name); + return -1; + } + + ifnamelen = strlen(ifname); + if (ifnamelen >= sizeof(ifr.ifr_name)) { + RTE_LOG(ERR, PMD, + "%s: I/F name too long (%s)\n", + name, ifname); + return -1; } if (framesize > blocksize) { @@ -904,7 +909,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, framesize, framecount, qdisc_bypass, &internals, ð_dev, - kvlist) < 0) + ifname) < 0) return -1; eth_dev->rx_pkt_burst = eth_af_packet_rx; From patchwork Tue Nov 20 10:26:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Lam, Tiago" X-Patchwork-Id: 48202 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 19A485681; Tue, 20 Nov 2018 11:26:54 +0100 (CET) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 54FC8322C for ; Tue, 20 Nov 2018 11:26:50 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Nov 2018 02:26:49 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,256,1539673200"; d="scan'208";a="90712036" Received: from silpixa00399125.ir.intel.com ([10.237.223.34]) by orsmga007.jf.intel.com with ESMTP; 20 Nov 2018 02:26:48 -0800 From: Tiago Lam To: dev@dpdk.org Cc: ferruh.yigit@intel.com, linville@tuxdriver.com, Tiago Lam Date: Tue, 20 Nov 2018 10:26:31 +0000 Message-Id: <1542709592-215007-3-git-send-email-tiago.lam@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542709592-215007-1-git-send-email-tiago.lam@intel.com> References: <1542707697-175836-1-git-send-email-tiago.lam@intel.com> <1542709592-215007-1-git-send-email-tiago.lam@intel.com> Subject: [dpdk-dev] [PATCH v2 3/3] net/af_packet: get 'framesz' from the iface's MTU 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" Use the underlying MTU to calculate the framsize to be used for the mmap RINGs. This is to make it more flexible on deployments with different MTU requirements, instead of using a pre-defined value of 2048B. If a 'framsz' option is provided, that value is used instead and the MTU of the underlying interface is ignored. Signed-off-by: Tiago Lam --- v2: Fix checkpatches.sh and check-git-log.sh warnings. --- drivers/net/af_packet/rte_eth_af_packet.c | 33 ++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 8d749a2..5549211 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -788,7 +788,7 @@ rte_eth_from_packet(struct rte_vdev_device *dev, unsigned k_idx; unsigned int blockcount; unsigned int blocksize = DFLT_BLOCK_SIZE; - unsigned int framesize = DFLT_FRAME_SIZE; + unsigned int framesize = 0; unsigned int framecount = DFLT_FRAME_COUNT; unsigned int qpairs = 1; unsigned int qdisc_bypass = 1; @@ -877,17 +877,40 @@ rte_eth_from_packet(struct rte_vdev_device *dev, } ifnamelen = strlen(ifname); - if (ifnamelen >= sizeof(ifr.ifr_name)) { + if (ifnamelen < sizeof(ifr.ifr_name)) { + memcpy(ifr.ifr_name, ifname, ifnamelen); + ifr.ifr_name[ifnamelen] = '\0'; + } else { RTE_LOG(ERR, PMD, "%s: I/F name too long (%s)\n", name, ifname); return -1; } + /* + * Base framesize on the MTU of the underlying interface, if no + * 'framesz' option is given + */ + if (!framesize) { + if (ioctl(*sockfd, SIOCGIFMTU, &ifr) == -1) { + RTE_LOG(ERR, PMD, + "%s: ioctl failed (SIOCGIFMTU)", + name); + framesize = DFLT_FRAME_SIZE; + } else { + framesize = ifr.ifr_mtu; + /* + * Align to TPACKET_ALIGNMENT and add TPACKET2_HDRLEN, + * to account for the extra needed space + */ + framesize = TPACKET_ALIGN(framesize + TPACKET2_HDRLEN); + } + } + if (framesize > blocksize) { - PMD_LOG(ERR, - "%s: AF_PACKET MMAP frame size exceeds block size!", - name); + RTE_LOG(ERR, PMD, + "%s: AF_PACKET MMAP frame size (%u) exceeds block size (%u)!", + name, framesize, blocksize); return -1; }