From patchwork Tue Feb 2 02:24:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375952 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24805C433DB for ; Tue, 2 Feb 2021 02:24:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7CC964EE2 for ; Tue, 2 Feb 2021 02:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229704AbhBBCY3 (ORCPT ); Mon, 1 Feb 2021 21:24:29 -0500 Received: from mga09.intel.com ([134.134.136.24]:11645 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhBBCY2 (ORCPT ); Mon, 1 Feb 2021 21:24:28 -0500 IronPort-SDR: OcSl9U0MOMQMcvzhQcV0Oek1SHaeBzasTCYI8EkIew73SgOBJ6KIpopXerrZ8muXm+LRKY2SHZ jzH16ZrGA9Tg== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929263" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929263" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:38 -0800 IronPort-SDR: 8i0H+v6QgmsZN0gdJJOaSbpvXvM6rnf+X4cZ6DMimyHGOJu09nk0uUloQwnni2GBYzmaKyxWEa sKMlHSE3ry5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782130" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:38 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Cristian Dumitrescu , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Kiran Bhandare Subject: [PATCH net-next 1/6] i40e: remove unnecessary memory writes of the next to clean pointer Date: Mon, 1 Feb 2021 18:24:15 -0800 Message-Id: <20210202022420.1328397-2-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Cristian Dumitrescu For performance reasons, avoid writing the ring next-to-clean pointer value back to memory on every update, as it is not really necessary. Instead, simply read it at initialization into a local copy, update the local copy as necessary and write the local copy back to memory after the last update. Signed-off-by: Cristian Dumitrescu Tested-by: Kiran Bhandare Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 492ce213208d..87d43407653c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -261,18 +261,6 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, return skb; } -/** - * i40e_inc_ntc: Advance the next_to_clean index - * @rx_ring: Rx ring - **/ -static void i40e_inc_ntc(struct i40e_ring *rx_ring) -{ - u32 ntc = rx_ring->next_to_clean + 1; - - ntc = (ntc < rx_ring->count) ? ntc : 0; - rx_ring->next_to_clean = ntc; -} - /** * i40e_clean_rx_irq_zc - Consumes Rx packets from the hardware ring * @rx_ring: Rx ring @@ -284,6 +272,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) { unsigned int total_rx_bytes = 0, total_rx_packets = 0; u16 cleaned_count = I40E_DESC_UNUSED(rx_ring); + u16 next_to_clean = rx_ring->next_to_clean; + u16 count_mask = rx_ring->count - 1; unsigned int xdp_res, xdp_xmit = 0; bool failure = false; struct sk_buff *skb; @@ -294,7 +284,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) unsigned int size; u64 qword; - rx_desc = I40E_RX_DESC(rx_ring, rx_ring->next_to_clean); + rx_desc = I40E_RX_DESC(rx_ring, next_to_clean); qword = le64_to_cpu(rx_desc->wb.qword1.status_error_len); /* This memory barrier is needed to keep us from reading @@ -307,11 +297,11 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) i40e_clean_programming_status(rx_ring, rx_desc->raw.qword[0], qword); - bi = i40e_rx_bi(rx_ring, rx_ring->next_to_clean); + bi = i40e_rx_bi(rx_ring, next_to_clean); xsk_buff_free(*bi); *bi = NULL; cleaned_count++; - i40e_inc_ntc(rx_ring); + next_to_clean = (next_to_clean + 1) & count_mask; continue; } @@ -320,7 +310,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) if (!size) break; - bi = i40e_rx_bi(rx_ring, rx_ring->next_to_clean); + bi = i40e_rx_bi(rx_ring, next_to_clean); (*bi)->data_end = (*bi)->data + size; xsk_buff_dma_sync_for_cpu(*bi, rx_ring->xsk_pool); @@ -336,7 +326,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) total_rx_packets++; cleaned_count++; - i40e_inc_ntc(rx_ring); + next_to_clean = (next_to_clean + 1) & count_mask; continue; } @@ -355,7 +345,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) *bi = NULL; cleaned_count++; - i40e_inc_ntc(rx_ring); + next_to_clean = (next_to_clean + 1) & count_mask; if (eth_skb_pad(skb)) continue; @@ -367,6 +357,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) napi_gro_receive(&rx_ring->q_vector->napi, skb); } + rx_ring->next_to_clean = next_to_clean; + if (cleaned_count >= I40E_RX_BUFFER_WRITE) failure = !i40e_alloc_rx_buffers_zc(rx_ring, cleaned_count); @@ -374,7 +366,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) i40e_update_rx_stats(rx_ring, total_rx_bytes, total_rx_packets); if (xsk_uses_need_wakeup(rx_ring->xsk_pool)) { - if (failure || rx_ring->next_to_clean == rx_ring->next_to_use) + if (failure || next_to_clean == rx_ring->next_to_use) xsk_set_rx_need_wakeup(rx_ring->xsk_pool); else xsk_clear_rx_need_wakeup(rx_ring->xsk_pool); From patchwork Tue Feb 2 02:24:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A627C433E0 for ; Tue, 2 Feb 2021 02:25:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0935564EE2 for ; Tue, 2 Feb 2021 02:25:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231168AbhBBCZM (ORCPT ); Mon, 1 Feb 2021 21:25:12 -0500 Received: from mga09.intel.com ([134.134.136.24]:11679 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbhBBCZK (ORCPT ); Mon, 1 Feb 2021 21:25:10 -0500 IronPort-SDR: xRG+p6mcxaMhdMwbCEePd7m3TEiqkxAH/3NcyJmuZVZznWUmbd1cYVH1e1J1LAlCcP38CRVaH5 5YSoIcFgJIXw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929267" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929267" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:39 -0800 IronPort-SDR: 73Hbcsr8WzX8Ix5niNrROTFaB/oN4a4kI4eKjmJO1+w+v4x888V6qKjdPRAB2UWv2kuvVfnVJC 7c1Ty2irjexA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782133" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:38 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Cristian Dumitrescu , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Kiran Bhandare Subject: [PATCH net-next 2/6] i40e: remove unnecessary cleaned_count updates Date: Mon, 1 Feb 2021 18:24:16 -0800 Message-Id: <20210202022420.1328397-3-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Cristian Dumitrescu For performance reasons, remove the redundant updates of the cleaned_count variable, as its value can be computed based on the ring next-to-clean variable, which is consistently updated. Signed-off-by: Cristian Dumitrescu Tested-by: Kiran Bhandare Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 87d43407653c..99082abd3000 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -300,7 +300,6 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) bi = i40e_rx_bi(rx_ring, next_to_clean); xsk_buff_free(*bi); *bi = NULL; - cleaned_count++; next_to_clean = (next_to_clean + 1) & count_mask; continue; } @@ -325,7 +324,6 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) total_rx_bytes += size; total_rx_packets++; - cleaned_count++; next_to_clean = (next_to_clean + 1) & count_mask; continue; } @@ -344,7 +342,6 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) } *bi = NULL; - cleaned_count++; next_to_clean = (next_to_clean + 1) & count_mask; if (eth_skb_pad(skb)) @@ -358,6 +355,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) } rx_ring->next_to_clean = next_to_clean; + cleaned_count = (next_to_clean - rx_ring->next_to_use - 1) & count_mask; if (cleaned_count >= I40E_RX_BUFFER_WRITE) failure = !i40e_alloc_rx_buffers_zc(rx_ring, cleaned_count); From patchwork Tue Feb 2 02:24:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375078 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58834C433DB for ; Tue, 2 Feb 2021 02:24:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1652464EDD for ; Tue, 2 Feb 2021 02:24:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbhBBCYq (ORCPT ); Mon, 1 Feb 2021 21:24:46 -0500 Received: from mga09.intel.com ([134.134.136.24]:11645 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbhBBCYo (ORCPT ); Mon, 1 Feb 2021 21:24:44 -0500 IronPort-SDR: PCldDL34U1I8qrfoKEY23NAiMwFK/vYyZqQ4h5c07IFG7ZCDuCFqymgAQ2YSOcl0FFjEnYbg7z IJZGuDnQuc+Q== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929268" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929268" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:39 -0800 IronPort-SDR: NKIwpKD72+HDiW8rG+LO24ST7Cd78ckziyvbRCFRdcboS/ckAd8kRWSpPcNYYZTgBVMuNzMds3 OOiLhM1ftKnA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782136" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:39 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Cristian Dumitrescu , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Kiran Bhandare Subject: [PATCH net-next 3/6] i40e: remove the redundant buffer info updates Date: Mon, 1 Feb 2021 18:24:17 -0800 Message-Id: <20210202022420.1328397-4-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Cristian Dumitrescu For performance reasons, remove the redundant buffer info updates (*bi = NULL). The buffers ready to be cleaned can easily be tracked based on the ring next-to-clean variable, which is consistently updated. Signed-off-by: Cristian Dumitrescu Tested-by: Kiran Bhandare Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 33 +++++++++------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 99082abd3000..1167496a2e08 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -280,7 +280,7 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) while (likely(total_rx_packets < (unsigned int)budget)) { union i40e_rx_desc *rx_desc; - struct xdp_buff **bi; + struct xdp_buff *bi; unsigned int size; u64 qword; @@ -297,9 +297,8 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) i40e_clean_programming_status(rx_ring, rx_desc->raw.qword[0], qword); - bi = i40e_rx_bi(rx_ring, next_to_clean); - xsk_buff_free(*bi); - *bi = NULL; + bi = *i40e_rx_bi(rx_ring, next_to_clean); + xsk_buff_free(bi); next_to_clean = (next_to_clean + 1) & count_mask; continue; } @@ -309,18 +308,17 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) if (!size) break; - bi = i40e_rx_bi(rx_ring, next_to_clean); - (*bi)->data_end = (*bi)->data + size; - xsk_buff_dma_sync_for_cpu(*bi, rx_ring->xsk_pool); + bi = *i40e_rx_bi(rx_ring, next_to_clean); + bi->data_end = bi->data + size; + xsk_buff_dma_sync_for_cpu(bi, rx_ring->xsk_pool); - xdp_res = i40e_run_xdp_zc(rx_ring, *bi); + xdp_res = i40e_run_xdp_zc(rx_ring, bi); if (xdp_res) { if (xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR)) xdp_xmit |= xdp_res; else - xsk_buff_free(*bi); + xsk_buff_free(bi); - *bi = NULL; total_rx_bytes += size; total_rx_packets++; @@ -335,13 +333,12 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) * BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that * SBP is *not* set in PRT_SBPVSI (default not set). */ - skb = i40e_construct_skb_zc(rx_ring, *bi); + skb = i40e_construct_skb_zc(rx_ring, bi); if (!skb) { rx_ring->rx_stats.alloc_buff_failed++; break; } - *bi = NULL; next_to_clean = (next_to_clean + 1) & count_mask; if (eth_skb_pad(skb)) @@ -594,16 +591,14 @@ int i40e_xsk_wakeup(struct net_device *dev, u32 queue_id, u32 flags) void i40e_xsk_clean_rx_ring(struct i40e_ring *rx_ring) { - u16 i; - - for (i = 0; i < rx_ring->count; i++) { - struct xdp_buff *rx_bi = *i40e_rx_bi(rx_ring, i); + u16 count_mask = rx_ring->count - 1; + u16 ntc = rx_ring->next_to_clean; + u16 ntu = rx_ring->next_to_use; - if (!rx_bi) - continue; + for ( ; ntc != ntu; ntc = (ntc + 1) & count_mask) { + struct xdp_buff *rx_bi = *i40e_rx_bi(rx_ring, ntc); xsk_buff_free(rx_bi); - rx_bi = NULL; } } From patchwork Tue Feb 2 02:24:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D9B31C433DB for ; Tue, 2 Feb 2021 02:25:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8170E64EE2 for ; Tue, 2 Feb 2021 02:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230210AbhBBCZC (ORCPT ); Mon, 1 Feb 2021 21:25:02 -0500 Received: from mga09.intel.com ([134.134.136.24]:11645 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229596AbhBBCZA (ORCPT ); Mon, 1 Feb 2021 21:25:00 -0500 IronPort-SDR: 4UFglLBIMeStLe1aA+YmmqUK2EL9tWrK+HD/EltJhQOpgTYVdV8uDgMrojrF1kBKDYFGF/tNvS gc1p/etdLWdQ== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929269" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929269" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:39 -0800 IronPort-SDR: jFEMF6d1JwiTpPZigTzLBgHAhLRQWVsf/v0RcCTxSBM7HlRhX9bha7/jM1dzPAXmFbPuH6D3Gz 3IEjyL4Gp3cg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782141" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:39 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Cristian Dumitrescu , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Kiran Bhandare Subject: [PATCH net-next 4/6] i40e: consolidate handling of XDP program actions Date: Mon, 1 Feb 2021 18:24:18 -0800 Message-Id: <20210202022420.1328397-5-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Cristian Dumitrescu Consolidate the actions performed on the packet based on the XDP program result into a separate function that is easier to read and maintain. Simplify the i40e_construct_skb_zc function, so that the input xdp buffer is always freed, regardless of whether the output skb is successfully created or not. Simplify the behavior of the i40e_clean_rx_irq_zc function, so that the current packet descriptor is dropped when function i40_construct_skb_zc returns an error as opposed to re-processing the same description on the next invocation. Signed-off-by: Cristian Dumitrescu Tested-by: Kiran Bhandare Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 98 ++++++++++++++-------- 1 file changed, 61 insertions(+), 37 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 1167496a2e08..470b8600adb1 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -250,17 +250,70 @@ static struct sk_buff *i40e_construct_skb_zc(struct i40e_ring *rx_ring, xdp->data_end - xdp->data_hard_start, GFP_ATOMIC | __GFP_NOWARN); if (unlikely(!skb)) - return NULL; + goto out; skb_reserve(skb, xdp->data - xdp->data_hard_start); memcpy(__skb_put(skb, datasize), xdp->data, datasize); if (metasize) skb_metadata_set(skb, metasize); +out: xsk_buff_free(xdp); return skb; } +static void i40e_handle_xdp_result_zc(struct i40e_ring *rx_ring, + struct xdp_buff *xdp_buff, + union i40e_rx_desc *rx_desc, + unsigned int *rx_packets, + unsigned int *rx_bytes, + unsigned int size, + unsigned int xdp_res) +{ + struct sk_buff *skb; + + *rx_packets = 1; + *rx_bytes = size; + + if (likely(xdp_res == I40E_XDP_REDIR) || xdp_res == I40E_XDP_TX) + return; + + if (xdp_res == I40E_XDP_CONSUMED) { + xsk_buff_free(xdp_buff); + return; + } + + if (xdp_res == I40E_XDP_PASS) { + /* NB! We are not checking for errors using + * i40e_test_staterr with + * BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that + * SBP is *not* set in PRT_SBPVSI (default not set). + */ + skb = i40e_construct_skb_zc(rx_ring, xdp_buff); + if (!skb) { + rx_ring->rx_stats.alloc_buff_failed++; + *rx_packets = 0; + *rx_bytes = 0; + return; + } + + if (eth_skb_pad(skb)) { + *rx_packets = 0; + *rx_bytes = 0; + return; + } + + *rx_bytes = skb->len; + i40e_process_skb_fields(rx_ring, rx_desc, skb); + napi_gro_receive(&rx_ring->q_vector->napi, skb); + return; + } + + /* Should never get here, as all valid cases have been handled already. + */ + WARN_ON_ONCE(1); +} + /** * i40e_clean_rx_irq_zc - Consumes Rx packets from the hardware ring * @rx_ring: Rx ring @@ -276,10 +329,11 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) u16 count_mask = rx_ring->count - 1; unsigned int xdp_res, xdp_xmit = 0; bool failure = false; - struct sk_buff *skb; while (likely(total_rx_packets < (unsigned int)budget)) { union i40e_rx_desc *rx_desc; + unsigned int rx_packets; + unsigned int rx_bytes; struct xdp_buff *bi; unsigned int size; u64 qword; @@ -313,42 +367,12 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) xsk_buff_dma_sync_for_cpu(bi, rx_ring->xsk_pool); xdp_res = i40e_run_xdp_zc(rx_ring, bi); - if (xdp_res) { - if (xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR)) - xdp_xmit |= xdp_res; - else - xsk_buff_free(bi); - - total_rx_bytes += size; - total_rx_packets++; - - next_to_clean = (next_to_clean + 1) & count_mask; - continue; - } - - /* XDP_PASS path */ - - /* NB! We are not checking for errors using - * i40e_test_staterr with - * BIT(I40E_RXD_QW1_ERROR_SHIFT). This is due to that - * SBP is *not* set in PRT_SBPVSI (default not set). - */ - skb = i40e_construct_skb_zc(rx_ring, bi); - if (!skb) { - rx_ring->rx_stats.alloc_buff_failed++; - break; - } - + i40e_handle_xdp_result_zc(rx_ring, bi, rx_desc, &rx_packets, + &rx_bytes, size, xdp_res); + total_rx_packets += rx_packets; + total_rx_bytes += rx_bytes; + xdp_xmit |= xdp_res & (I40E_XDP_TX | I40E_XDP_REDIR); next_to_clean = (next_to_clean + 1) & count_mask; - - if (eth_skb_pad(skb)) - continue; - - total_rx_bytes += skb->len; - total_rx_packets++; - - i40e_process_skb_fields(rx_ring, rx_desc, skb); - napi_gro_receive(&rx_ring->q_vector->napi, skb); } rx_ring->next_to_clean = next_to_clean; From patchwork Tue Feb 2 02:24:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375950 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74ECCC433E0 for ; Tue, 2 Feb 2021 02:25:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2D35864EE4 for ; Tue, 2 Feb 2021 02:25:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231286AbhBBCZ1 (ORCPT ); Mon, 1 Feb 2021 21:25:27 -0500 Received: from mga09.intel.com ([134.134.136.24]:11689 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbhBBCZZ (ORCPT ); Mon, 1 Feb 2021 21:25:25 -0500 IronPort-SDR: O2+WR2+27qk3Odp9ldkZbtgVioWiR6kktFkP/yUiUFQlUlx/2eD+BzSJkKX47AqTlFi8TRgXI6 LV0YQOnG9LEw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929271" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929271" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:40 -0800 IronPort-SDR: +DsLSya6oP8e9yDQBB7bbhbxBQ0QVOLRPYNbetlVh9CI3SlNLL5/CwCLHMy9vj3z99+1MjNiwK EOzwPwAv8tGA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782145" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:39 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Arkadiusz Kubalewski , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Aleksandr Loktionov , George Kuruvinakunnel Subject: [PATCH net-next 5/6] i40e: Add info trace at loading XDP program Date: Mon, 1 Feb 2021 18:24:19 -0800 Message-Id: <20210202022420.1328397-6-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Arkadiusz Kubalewski New trace indicates that the XDP program was loaded. The trace has a note that in case of using XDP_REDIRECT, number of queues on both interfaces shall be the same. This is required for optimal performance of XDP_REDIRECT, if interface used for TX has lower number of queues than a RX interface, the packets may be dropped (depending on RSS queue assignment). Signed-off-by: Arkadiusz Kubalewski Signed-off-by: Aleksandr Loktionov Tested-by: George Kuruvinakunnel Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 521ea9df38d5..f35bd9164106 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -12489,11 +12489,14 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, /* Kick start the NAPI context if there is an AF_XDP socket open * on that queue id. This so that receiving will start. */ - if (need_reset && prog) + if (need_reset && prog) { + dev_info(&pf->pdev->dev, + "Loading XDP program, please note: XDP_REDIRECT action requires the same number of queues on both interfaces\n"); for (i = 0; i < vsi->num_queue_pairs; i++) if (vsi->xdp_rings[i]->xsk_pool) (void)i40e_xsk_wakeup(vsi->netdev, i, XDP_WAKEUP_RX); + } return 0; } From patchwork Tue Feb 2 02:24:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Nguyen X-Patchwork-Id: 375075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C56BC433DB for ; Tue, 2 Feb 2021 02:25:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DCF364EE4 for ; Tue, 2 Feb 2021 02:25:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229843AbhBBCZf (ORCPT ); Mon, 1 Feb 2021 21:25:35 -0500 Received: from mga09.intel.com ([134.134.136.24]:11679 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231128AbhBBCZ0 (ORCPT ); Mon, 1 Feb 2021 21:25:26 -0500 IronPort-SDR: WtGidEPe52GAS8K7qAlY9F0CE7b387Q1OXgUNAIucktdYikZu6ZcoivDiD9HJ1NDc6rvnm6K5a ALHUuiBgeDBg== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180929272" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180929272" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:23:40 -0800 IronPort-SDR: qIAJuSV0FgCqFATnuenuxbpURWRXkPB/8PJAkzG3pxjn+UWDo8R/negCpTRa1MTgDIDf82mGz9 LMas1nSpqekw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="581782148" Received: from anguy11-desk2.jf.intel.com ([10.166.244.147]) by fmsmga005.fm.intel.com with ESMTP; 01 Feb 2021 18:23:40 -0800 From: Tony Nguyen To: davem@davemloft.net, kuba@kernel.org Cc: Eryk Rybak , netdev@vger.kernel.org, sassmann@redhat.com, anthony.l.nguyen@intel.com, bjorn.topel@intel.com, maciej.fijalkowski@intel.com, magnus.karlsson@intel.com, Aleksandr Loktionov , Kiran Bhandare Subject: [PATCH net-next 6/6] i40e: Log error for oversized MTU on device Date: Mon, 1 Feb 2021 18:24:20 -0800 Message-Id: <20210202022420.1328397-7-anthony.l.nguyen@intel.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> References: <20210202022420.1328397-1-anthony.l.nguyen@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eryk Rybak When attempting to link XDP prog with MTU larger than supported, user is not informed why XDP linking fails. Adding proper error message: "MTU too large to enable XDP". Due to the lack of support for non-static variables in netlinks extended ACK feature, additional information has been added to dmesg to better inform about invalid MTU setting. Signed-off-by: Aleksandr Loktionov Signed-off-by: Eryk Rybak Tested-by: Kiran Bhandare Signed-off-by: Tony Nguyen --- drivers/net/ethernet/intel/i40e/i40e_main.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index f35bd9164106..b52a324a9f28 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -12448,9 +12448,10 @@ static netdev_features_t i40e_features_check(struct sk_buff *skb, * i40e_xdp_setup - add/remove an XDP program * @vsi: VSI to changed * @prog: XDP program + * @extack: netlink extended ack **/ -static int i40e_xdp_setup(struct i40e_vsi *vsi, - struct bpf_prog *prog) +static int i40e_xdp_setup(struct i40e_vsi *vsi, struct bpf_prog *prog, + struct netlink_ext_ack *extack) { int frame_size = vsi->netdev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; struct i40e_pf *pf = vsi->back; @@ -12459,8 +12460,13 @@ static int i40e_xdp_setup(struct i40e_vsi *vsi, int i; /* Don't allow frames that span over multiple buffers */ - if (frame_size > vsi->rx_buf_len) + if (frame_size > vsi->rx_buf_len) { + NL_SET_ERR_MSG_MOD(extack, "MTU too large to enable XDP"); + dev_info(&pf->pdev->dev, + "MTU of %u bytes is too large to enable XDP (maximum: %u bytes)\n", + vsi->netdev->mtu, vsi->rx_buf_len); return -EINVAL; + } if (!i40e_enabled_xdp_vsi(vsi) && !prog) return 0; @@ -12772,7 +12778,7 @@ static int i40e_xdp(struct net_device *dev, switch (xdp->command) { case XDP_SETUP_PROG: - return i40e_xdp_setup(vsi, xdp->prog); + return i40e_xdp_setup(vsi, xdp->prog, xdp->extack); case XDP_SETUP_XSK_POOL: return i40e_xsk_pool_setup(vsi, xdp->xsk.pool, xdp->xsk.queue_id);