From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00052.outbound.protection.outlook.com [40.107.0.52]) by dpdk.org (Postfix) with ESMTP id A3A4B2C18 for ; Sat, 6 May 2017 03:20:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Mellanox.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=SfRR7UetRzk29GuWHlH4N/6wbTu4nqYiRUios24U5F8=; b=Kqh+9upngn0aLjilYXESkp+kCjD0HwxZZFN7vJfvOyP9qTKUpLNoGlE6GptgukA3mcJhjpW1TD5S4ae8MA4+rgJXoE/VAklAjQd0x/mLPrE41toV6gR8KHNuYIcLtMb5ya1B3xpvVbOuLGhFrKPTXffeIrgqnANv7nsuX6CjUsw= Authentication-Results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=mellanox.com; Received: from mellanox.com (12.250.235.110) by VI1PR0501MB2046.eurprd05.prod.outlook.com (10.167.195.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1075.11; Sat, 6 May 2017 01:20:31 +0000 From: Yongseok Koh To: CC: , , , , Yongseok Koh Date: Fri, 5 May 2017 18:20:18 -0700 Message-ID: <20170506012018.18579-1-yskoh@mellanox.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [12.250.235.110] X-ClientProxiedBy: BN6PR11CA0005.namprd11.prod.outlook.com (10.172.17.15) To VI1PR0501MB2046.eurprd05.prod.outlook.com (10.167.195.148) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 17b0c7d9-9a06-4103-c4c6-08d4941e17a5 X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(48565401081)(201703131423075)(201703031133081); SRVR:VI1PR0501MB2046; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2046; 3:IH/dnFiM+p1f4oeGnfpcuY21a/F3IYOJKnKFQDFaIIobukx2VlmSKWAwik+P1+DwfjtdtylMzQO+AobiCZRikR6mzwl2ndbi4X7OMg+KUj5H6uBM7UkpcmKybrCWw8WBSxzpznQMac+vdBc61VTzIeWe2nEL9VE5/Bpz3/nTz27baq4mOAiHX8EK382cZgx78sYyKyD0PGJ2FzGefbhRGkTM2jknIP6pBlE2X3/2SyDg0kcUYsC8DwpRv4B532TQr+0JJnOt61w3y0jRUKUWo9G9Th3nJ+SzFZFPihCjLC45B1PdeCMPdZpAtOEETSZ+AMtjDvg2MLpTZ1B4oEkSAkt/X+FjP5JcFbtYxMP22ns=; 25:s4XlMdGD1zgHA0U+qrNY+vWyMZdGR9ZIoYr91dkv8ArKKhpkkP3JOY40vvOyOZaVGPMxuZkbmrCeyRDq++HRQfao9uzeVNEWTIkhtuixwhlFHEtBfRPvgst4OSvQnksdb+Tzw/7KeFC7k+5kx4Z0TE2+FNSOBcQgb7YkB9wz7gUwa3XngT86JK6DdumZIJ1jCTCaYqZN69qfUfrMQofimcrs+XnsyECDqTbpbzw2tVIqBjLG33S8SUmhplaRg7tQJ5HpcHJNF2IZvzllUe4QStSUeG/muAKJvrpoq1HZ2prMW/UfQXYcRedai3xeWPs+zRk8DGolHV7U1C2si6RPCBqwbRl6J7I57BYnOZvpFAq/++JIchP+kI77PdZwXEqNWa1wS4Rjyx6nX5oaWPnmQEc7Z5ImRpM5KOJHXkvLsWQdX2jtALZryIgwnsmbQZ20FTetqlcUtEq9pjQBjPClFefAX4xMcAiFO/3ZC4YlOEs= X-LD-Processed: a652971c-7d2e-4d9b-a6a4-d149256f461b,ExtAddr X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2046; 31:NkCqljo2AwJimqmUfjKK4O9OufiSNiXc3w2HLyKMdqBpL0Yv92bxmhPXGsxRoP2uDjzw/nwIBNmPRI6a+I2hMyop8n+Iw/s7RqPrlhamzTC+FouI2lUr2+pxbgZWrqW1Om4Vje5A+9KsMib9Rrq65/2sfw2yL5zVswc5HF1RHJ5hzcTpE02Z/0XqL+aQjWQ00qo70J/2z09+8iSyt4ulYzsH3ivHs49Bi2Ma+GiPu0Q=; 20:j11XUjxIct5G+slI+9BirHlsZE/8HwE3m/brnLZE9bVR/Z7lt7FX4J+d0RXwDNTK5GgnBUye8YbG7UFBOi4sH9bl4cwqOQuh1z7jYEKIks1k+HLy7WMZzx+kxBOK5OtS7v2y43HHAUnprGAo95x3gEI9boyUnKHTzClXHeBp7+xvkO9JUZGhlnZvoLyQzni9prurp3EP+PjpWnRgi1vO759kk/LWqsIvT0wAmJtwz7MkCTafXBBb+QfvCiDHF3kTphvOC55UIcKLS09Q1Zo7RDZwI8KOalbe1FtCBjKz9Vn8ZXS9FIoAlSaiplz+jzIREAF+VJvqL0NYUAV4bZqk3wU15T6DCF3cSLut80CEM7i576KloGnJPoNNTJzyafEJaBcXHLwXQ1XEch5KSCq3Unn9yhiB+toZOJhSCdyhuFsrSO7GqhPtLwnW1k2pvD9IZ3NEDHIVlEJviaf0oCBDbt5lNd3EzkmKA5JWKBMCPlUK1HAT7zAbmdyGqMuGZ4cw X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(95692535739014); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3002001)(6055026)(6041248)(20161123560025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123555025)(20161123558100)(6072148); SRVR:VI1PR0501MB2046; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0501MB2046; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2046; 4:RaKd/XlKhI4bmhkq9/IYOGQuPmxhrd3NmajPfEj1XjXiT+LJeVz4x1yekiUx+AOltRIBEakD63KvC+FXLCt5sc8KoKHmfsvgh6oFvq8UMmzMvUIoMHfoc3kKwffaLUwDVoYQiIMFgoKQ3LQyZ4eW0X5KmaCbDmSYSUSHoEWGVNLFpCozuH/bDFRRhBFqsMJYhMei7H6MZIRnKHAm3TG+pjHCUaB/ciYmI6g0Iz6OQVpUDNFoMNhF3L9kSJfYkkExQHN/iueU9P2Q9JWjpC1mQy2AjcePe2Umf5f6cL2oo8YEemUbRAXOvpsHPuI/Ti1sF+YLEKtliyv+2KhM7p2BFXVCrA/jm4Aff1aw8cCBi7s3gm//d6sa2qPNxYQ8o43puO6q30BMU2SegGCEt1wJxVlzwQ+VY3dPC5WaEvJ95phmP2qlTxxEO5BcQtcTbY4Q16Zwuc4ZC1KHfBdZNhAhV2Z6giPnHtsRUXfWoxVxq0QJl/rfainPwCWR+hDa8ZatEQ4cUX/zGtTxw16AxmGLpoDxh41Vy525ddEIxIxURNKe5IcW+bfi2ygKicqMW7S9EvrZooqTkI/v/GW5KU1r01ts/fc+9tmkc9IUJk8NT8FpiOXLhkme/nMIJC4MOnsArABhy8UAhUmFNFSTk2b6n4QD/cKp2CJ97LJzmt/QEg5LntGvvNtE7qu+C1qq7xD+DZOUSSTuKMjlave7XpEoX/pjVfOw65gjlZkAvOFR7X9VAUjddoQkhEQ+9nKCGEaifuJ2kRTTx/4CqfP53Ovef9wYXa+ZKh/PyLnGPI/MGTFpkYN7vV2PPr+uedeiWRr7NhLor8e8CkW/AhGJRTweFwWaYdWXXs/QIofmvqvgiCY= X-Forefront-PRVS: 029976C540 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(4630300001)(6009001)(39450400003)(39840400002)(39860400002)(39410400002)(39850400002)(39400400002)(25786009)(478600001)(4326008)(50986999)(53936002)(55016002)(5003940100001)(86362001)(50226002)(54906002)(42186005)(81166006)(38730400002)(107886003)(110136004)(8676002)(7736002)(305945005)(3846002)(5660300001)(189998001)(1076002)(6116002)(33646002)(6666003)(50466002)(48376002)(33026002)(47776003)(66066001)(2351001)(2906002)(36756003)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR0501MB2046; H:mellanox.com; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0501MB2046; 23:WhuqwXcA/V7sF1eWDppHWNP+RJy3eJCZFnods4J?= =?us-ascii?Q?qptK4ti6Ca8anevMOowHthZJSZ4a2HwWV+9SXv6Da7+54AZ4IrNPpxaC0XYO?= =?us-ascii?Q?GUBGgQhaUJEIFgtPJKbI9tYWLC3N5TmP09krWWy00OY1TKTAnYbpDy5XRGvA?= =?us-ascii?Q?3bTTVsJCb+jeWpIRE+5JoTd6oGwGkeHxGIohS/26lJ8/wee7fC+LLq0vEYFI?= =?us-ascii?Q?OpsuLLu8KjOEj+2NPxH0HbHFmqQoawliWYdHSr5N6Xibf+Gp1VIk31oY9s8r?= =?us-ascii?Q?S94eDSaNDtzLBxiPFsmqrUnmS4p5Q7RQWWUTRAYwcRQjrte3ag9lqCkwONOz?= =?us-ascii?Q?0h0ftoOQqT3REsZfEr160QEPPHoJSOQJ9Gl8J6uOvEiJm0jdI1/HmxVlFR0K?= =?us-ascii?Q?RFuT3Gqm1Ktwn0dspRN7nouh4vDTpr7qrglNlu+DLdO18jKXOCRwSUmhhBVW?= =?us-ascii?Q?b/LBGrCCJ81U2V50p1PU4qj1a/K5GARjZfTGIVcxo3Jz0KN/Bw5IuXpOdsYH?= =?us-ascii?Q?P5JEuTH5jRl7XtH/C1w10Mh70Q3w2f3Vyh2OU48U8RpjV8lkLp0cx1sNMT5U?= =?us-ascii?Q?4qoOtbhJao1Hrad6r5CukDQm5DfIdV/r5M/g1oEj+Tb4cNPbeSpVxre1YZj1?= =?us-ascii?Q?fImWSu7W4TbSUsHhSq+7f025Og3oXwZI1+JRKThn6Bce1YqYikprVw+scIFP?= =?us-ascii?Q?22hnHBEvqmqdi6Z6TCHftk0uMnmrajwBEN2LBoTDG3JVRctG3Ms4B+w8aTXL?= =?us-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GkNlikcHs5ktgHQVGdQAFSvvNJ0A8WCl9H1hCwXQNMx50n3hQg3Gh9IN3vZufxnYM0QjtkKCoav7+UA==; 24:i6K9Gv3Gt53IIBwPQCQi34o1Op/HGgnYIfg9VsI7V0KELuUgHyZlio2KsQbHeKYEK3vM3/TQYFXyAIpd8z+i/wmpjtXDQMZmg6IxQvXjqKM= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0501MB2046; 7:FrgkMYT0ty0LjbAytMa/dkDr2lya+zkf3yMg2xx7UA2V8tnK6mZSAlt62sytnQpssE2Zcc8mzaMPX1DC9bALS82x1wwAZhz1DofDToz+aF0RC1Bm/rccEYlnWiVS/0wGhnsebreTd5G+ojN27w++vCH/ERhhreCYP+CVKEfnXYcWE5ZuzLeDRFxNbZ6ZcDaw3iIR6iNBSROMfPkwUJgoj/fkGTzhtjGlaMnGqZexIt2CFZ9c6KQHzVVNkD8rcpRewSv5ipVO4c3cmQtjc4c0bLgGbDoSBMVVZA7g5sPbv1gxa5A2tRJ5mHtzaZiczjEXk2qxYB/kJ4G9PhVBZFV27A== X-OriginatorOrg: Mellanox.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2017 01:20:31.9314 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0501MB2046 Subject: [dpdk-dev] [PATCH] net/mlx5: fix erroneous index handling for Tx ring 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: , X-List-Received-Date: Sat, 06 May 2017 01:20:43 -0000 In case of resource deficiency on Tx, mlx5_tx_burst() breaks the loop without rolling back consumed resources (txq->wqes[] and txq->elts[]). This can make application crash because unposted mbufs can be freed while processing completions. In regard to this, some error-prone/redundant indexing has been cleaned as well. Reported-by: Hanoch Haim Signed-off-by: Yongseok Koh --- drivers/net/mlx5/mlx5_rxtx.c | 50 +++++++++++++++++++------------------------- 1 file changed, 21 insertions(+), 29 deletions(-) diff --git a/drivers/net/mlx5/mlx5_rxtx.c b/drivers/net/mlx5/mlx5_rxtx.c index 6254228a9..d7176a422 100644 --- a/drivers/net/mlx5/mlx5_rxtx.c +++ b/drivers/net/mlx5/mlx5_rxtx.c @@ -493,7 +493,6 @@ uint16_t mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) { struct txq *txq = (struct txq *)dpdk_txq; - uint16_t elts_head = txq->elts_head; const unsigned int elts_n = 1 << txq->elts_n; unsigned int i = 0; unsigned int j = 0; @@ -504,6 +503,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) uint16_t max_wqe; unsigned int comp; volatile struct mlx5_wqe_v *wqe = NULL; + volatile struct mlx5_wqe_ctrl *last_wqe = NULL; unsigned int segs_n = 0; struct rte_mbuf *buf = NULL; uint8_t *raw; @@ -514,7 +514,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) rte_prefetch0(*pkts); /* Start processing. */ txq_complete(txq); - max = (elts_n - (elts_head - txq->elts_tail)); + max = (elts_n - (txq->elts_head - txq->elts_tail)); if (max > elts_n) max -= elts_n; max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi); @@ -524,8 +524,10 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) volatile rte_v128u32_t *dseg = NULL; uint32_t length; unsigned int ds = 0; + unsigned int sg = 0; uintptr_t addr; uint64_t naddr; + uint16_t elts_head = (txq->elts_head + i + j) & (elts_n - 1); uint16_t pkt_inline_sz = MLX5_WQE_DWORD_SIZE + 2; uint16_t tso_header_sz = 0; uint16_t ehdr; @@ -536,7 +538,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) #endif /* first_seg */ - buf = *(pkts++); + buf = *(pkts + i); segs_n = buf->nb_segs; /* * Make sure there is enough room to store this packet and @@ -547,15 +549,13 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) break; max -= segs_n; --segs_n; - if (!segs_n) - --pkts_n; if (unlikely(--max_wqe == 0)) break; wqe = (volatile struct mlx5_wqe_v *) tx_mlx5_wqe(txq, txq->wqe_ci); rte_prefetch0(tx_mlx5_wqe(txq, txq->wqe_ci + 1)); - if (pkts_n > 1) - rte_prefetch0(*pkts); + if (pkts_n - i > 1) + rte_prefetch0(*(pkts + i + 1)); addr = rte_pktmbuf_mtod(buf, uintptr_t); length = DATA_LEN(buf); ehdr = (((uint8_t *)addr)[1] << 8) | @@ -567,14 +567,10 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) break; /* Update element. */ (*txq->elts)[elts_head] = buf; - elts_head = (elts_head + 1) & (elts_n - 1); /* Prefetch next buffer data. */ - if (pkts_n > 1) { - volatile void *pkt_addr; - - pkt_addr = rte_pktmbuf_mtod(*pkts, volatile void *); - rte_prefetch0(pkt_addr); - } + if (pkts_n - i > 1) + rte_prefetch0( + rte_pktmbuf_mtod(*(pkts + i + 1), volatile void *)); /* Should we enable HW CKSUM offload */ if (buf->ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) { @@ -677,10 +673,6 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) }; ds = 1; total_length = 0; - pkts--; - pkts_n++; - elts_head = (elts_head - 1) & - (elts_n - 1); k++; goto next_wqe; } @@ -813,14 +805,15 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) naddr, naddr >> 32, }; - (*txq->elts)[elts_head] = buf; elts_head = (elts_head + 1) & (elts_n - 1); - ++j; + (*txq->elts)[elts_head] = buf; + ++sg; --segs_n; + /* Advance counter only if all segs are successfully posted. */ if (segs_n) goto next_seg; else - --pkts_n; + j += sg; next_pkt: ++i; /* Initialize known and common part of the WQE structure. */ @@ -853,24 +846,24 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) } next_wqe: txq->wqe_ci += (ds + 3) / 4; + /* Save the last successful WQE for completion request */ + last_wqe = (volatile struct mlx5_wqe_ctrl *)wqe; #ifdef MLX5_PMD_SOFT_COUNTERS /* Increment sent bytes counter. */ txq->stats.obytes += total_length; #endif - } while (pkts_n); + } while (i < pkts_n); /* Take a shortcut if nothing must be sent. */ if (unlikely((i + k) == 0)) return 0; + txq->elts_head = (txq->elts_head + i + j) & (elts_n - 1); /* Check whether completion threshold has been reached. */ comp = txq->elts_comp + i + j + k; if (comp >= MLX5_TX_COMP_THRESH) { - volatile struct mlx5_wqe_ctrl *w = - (volatile struct mlx5_wqe_ctrl *)wqe; - /* Request completion on last WQE. */ - w->ctrl2 = htonl(8); + last_wqe->ctrl2 = htonl(8); /* Save elts_head in unused "immediate" field of WQE. */ - w->ctrl3 = elts_head; + last_wqe->ctrl3 = txq->elts_head; txq->elts_comp = 0; } else { txq->elts_comp = comp; @@ -880,8 +873,7 @@ mlx5_tx_burst(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n) txq->stats.opackets += i; #endif /* Ring QP doorbell. */ - mlx5_tx_dbrec(txq, (volatile struct mlx5_wqe *)wqe); - txq->elts_head = elts_head; + mlx5_tx_dbrec(txq, (volatile struct mlx5_wqe *)last_wqe); return i; } -- 2.11.0