From patchwork Mon Jan 2 15:18:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13086776 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78D0FC5479D for ; Mon, 2 Jan 2023 15:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236096AbjABPTh (ORCPT ); Mon, 2 Jan 2023 10:19:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236323AbjABPTQ (ORCPT ); Mon, 2 Jan 2023 10:19:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5721F10A6 for ; Mon, 2 Jan 2023 07:19:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DC20760A24 for ; Mon, 2 Jan 2023 15:19:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EFFFCC433EF; Mon, 2 Jan 2023 15:19:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672672755; bh=7g/u2VMMIO9/7S3DkIGknPlGgh/bA7HKunZYs2JNXU0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VACg9w3c1JLaRv1H6caXWLvrKknPCwifpc88gDFPjPwLZEDKEVEYvzE3uI0vPgKvb al/Z6ZL26iu+/dKfO3m2nJ3XlmtBfgekPNvFHCb+x7PQjyiEOLkjPCLKlxnT84tqAP KAKetTzjNqNbWdJns8TIXh9YQkBJConvOibCqmvY/lEfQbE04prFVah+e8ZXGY/Vsm ErEUUm1ncGiNepncuqNoA7zLNfPYrQtAIggKh62dl39+c6Ls6UBysHOwSD41IJ1xE7 lu0ih7FZWOXlNtl5Kg6axlwIX6xpAstDb/6X6TIEaiDSChPPvsw1cpAEwZSgiQy05U sJHtosCHr8DPA== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lorenzo.bianconi@redhat.com, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com Subject: [PATCH net-next 1/3] net: ethernet: enetc: unlock XDP_REDIRECT for XDP non-linear buffers Date: Mon, 2 Jan 2023 16:18:51 +0100 Message-Id: <783a763dc5c92e1b4bbe72117bda83c14be060cc.1672672314.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Even if full XDP_REDIRECT is not supported yet for non-linear XDP buffers since we allow redirecting just into CPUMAPs, unlock XDP_REDIRECT for S/G XDP buffer and rely on XDP stack to properly take care of the frames. Tested-by: Vladimir Oltean Signed-off-by: Lorenzo Bianconi --- drivers/net/ethernet/freescale/enetc/enetc.c | 24 ++++++++------------ 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 3a79ead5219a..18a01f6282b6 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1412,6 +1412,16 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, /* To be used for XDP_TX */ rx_swbd->len = size; + if (!xdp_buff_has_frags(xdp_buff)) { + xdp_buff_set_frags_flag(xdp_buff); + shinfo->xdp_frags_size = size; + } else { + shinfo->xdp_frags_size += size; + } + + if (page_is_pfmemalloc(rx_swbd->page)) + xdp_buff_set_frag_pfmemalloc(xdp_buff); + skb_frag_off_set(frag, rx_swbd->page_offset); skb_frag_size_set(frag, size); __skb_frag_set_page(frag, rx_swbd->page); @@ -1584,20 +1594,6 @@ static int enetc_clean_rx_ring_xdp(struct enetc_bdr *rx_ring, } break; case XDP_REDIRECT: - /* xdp_return_frame does not support S/G in the sense - * that it leaks the fragments (__xdp_return should not - * call page_frag_free only for the initial buffer). - * Until XDP_REDIRECT gains support for S/G let's keep - * the code structure in place, but dead. We drop the - * S/G frames ourselves to avoid memory leaks which - * would otherwise leave the kernel OOM. - */ - if (unlikely(cleaned_cnt - orig_cleaned_cnt != 1)) { - enetc_xdp_drop(rx_ring, orig_i, i); - rx_ring->stats.xdp_redirect_sg++; - break; - } - err = xdp_do_redirect(rx_ring->ndev, &xdp_buff, prog); if (unlikely(err)) { enetc_xdp_drop(rx_ring, orig_i, i); From patchwork Mon Jan 2 15:18:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13086777 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A217C3DA7A for ; Mon, 2 Jan 2023 15:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236197AbjABPTj (ORCPT ); Mon, 2 Jan 2023 10:19:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236336AbjABPTX (ORCPT ); Mon, 2 Jan 2023 10:19:23 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD2B410B0 for ; Mon, 2 Jan 2023 07:19:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 61D0DB80C70 for ; Mon, 2 Jan 2023 15:19:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C6A96C433EF; Mon, 2 Jan 2023 15:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672672759; bh=5oZyVv3sIxKejDrYUiT1Nu/dIoe8s5jODZGWH1lQAR0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U21UkQCmSr6p2dYHITw1o8xh1u2yKdBk6sx4kjukjcCa/Qpgkh+krMeRSoPrbb/zL rdiAkjucwRI86GmPXKIkbNPQpRfODehtOk6xGy7jFIVbpV4cx1uXMUa/im1afTx4L/ zbM0nPqkYueWLUjJNjcpPGDNLHXTo658/J9lqnthcrMgMXPwR+LVNczGw0zGqhVOAE gEWOwUeMH2r67r8KSKZ7/hOPhZweeqtCatpxrbn1gsq790+pxzA/mwoKZRT2bghkZp fuXfEVUaCuL4OxefTPqboN77dkMlxOf507SWX5GVQu1ZMhY27LvxkEOlZlmtPOnTUa TY+d4X0bq5Z9w== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lorenzo.bianconi@redhat.com, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com Subject: [PATCH net-next 2/3] net: ethernet: enetc: get rid of xdp_redirect_sg counter Date: Mon, 2 Jan 2023 16:18:52 +0100 Message-Id: <1a6681949f1aa9271d6957bb48d2338ace454136.1672672314.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Remove xdp_redirect_sg counter and the related ethtool entry since it is no longer used. Tested-by: Vladimir Oltean Signed-off-by: Lorenzo Bianconi --- drivers/net/ethernet/freescale/enetc/enetc.h | 1 - drivers/net/ethernet/freescale/enetc/enetc_ethtool.c | 2 -- 2 files changed, 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.h b/drivers/net/ethernet/freescale/enetc/enetc.h index c6d8cc15c270..416e4138dbaf 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.h +++ b/drivers/net/ethernet/freescale/enetc/enetc.h @@ -70,7 +70,6 @@ struct enetc_ring_stats { unsigned int xdp_tx_drops; unsigned int xdp_redirect; unsigned int xdp_redirect_failures; - unsigned int xdp_redirect_sg; unsigned int recycles; unsigned int recycle_failures; unsigned int win_drop; diff --git a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c index c8369e3752b0..d45f305eb03c 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c +++ b/drivers/net/ethernet/freescale/enetc/enetc_ethtool.c @@ -197,7 +197,6 @@ static const char rx_ring_stats[][ETH_GSTRING_LEN] = { "Rx ring %2d recycle failures", "Rx ring %2d redirects", "Rx ring %2d redirect failures", - "Rx ring %2d redirect S/G", }; static const char tx_ring_stats[][ETH_GSTRING_LEN] = { @@ -291,7 +290,6 @@ static void enetc_get_ethtool_stats(struct net_device *ndev, data[o++] = priv->rx_ring[i]->stats.recycle_failures; data[o++] = priv->rx_ring[i]->stats.xdp_redirect; data[o++] = priv->rx_ring[i]->stats.xdp_redirect_failures; - data[o++] = priv->rx_ring[i]->stats.xdp_redirect_sg; } if (!enetc_si_is_pf(priv->si)) From patchwork Mon Jan 2 15:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 13086775 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64E72C3DA7A for ; Mon, 2 Jan 2023 15:19:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233341AbjABPTg (ORCPT ); Mon, 2 Jan 2023 10:19:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236339AbjABPTY (ORCPT ); Mon, 2 Jan 2023 10:19:24 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C32D10F9 for ; Mon, 2 Jan 2023 07:19:24 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id ACC3C60C2A for ; Mon, 2 Jan 2023 15:19:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD661C433D2; Mon, 2 Jan 2023 15:19:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672672763; bh=FWUohQqVxutaX+oxbGwEgZu0QqVwW0r5RqdR/kUxhlE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KM6ZYCVbbKKWbZrWFhMOk8Ub5E+F0S+sZRepEhlHnob1IT3Dsry6Kd/HHC5xRKrba WGZXuhWl6aIQ+kgrrcm5zArOBNvdvrt9d94+uZgm2RYmtaqpqv1W9CTEU25QKAc/7M RlNqTR9TOP6yQK7PwuyHmao2ywtiYfClMUt8KwSTXgPHVULN+tBKBdQUx8rvajEHTc sIXA0CmCh5Qc38/ozDP4ravD6o0Iq3X74eA166dvK7409YsB9s1zKAVH+7vgSV70lT NRVOwcG155KoBko8tKzF6YIaY0PTHHEiDDld3lnwfgB1Q1O72fThGXAq++ypg0kvsC vCxVVIBy2gaHg== From: Lorenzo Bianconi To: netdev@vger.kernel.org Cc: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, lorenzo.bianconi@redhat.com, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com Subject: [PATCH net-next 3/3] net: ethernet: enetc: do not always access skb_shared_info in the XDP path Date: Mon, 2 Jan 2023 16:18:53 +0100 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Move XDP skb_shared_info structure initialization in from enetc_map_rx_buff_to_xdp() to enetc_add_rx_buff_to_xdp() and do not always access skb_shared_info in the xdp_buff/xdp_frame since it is located in a different cacheline with respect to hard_start and data xdp pointers. Rely on XDP_FLAGS_HAS_FRAGS flag to check if it really necessary to access non-linear part of the xdp_buff/xdp_frame. Reviewed-by: Vladimir Oltean Tested-by: Vladimir Oltean Signed-off-by: Lorenzo Bianconi --- drivers/net/ethernet/freescale/enetc/enetc.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index 18a01f6282b6..5ad0b259e623 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -1305,6 +1305,10 @@ static int enetc_xdp_frame_to_xdp_tx_swbd(struct enetc_bdr *tx_ring, xdp_tx_swbd->xdp_frame = NULL; n++; + + if (!xdp_frame_has_frags(xdp_frame)) + goto out; + xdp_tx_swbd = &xdp_tx_arr[n]; shinfo = xdp_get_shared_info_from_frame(xdp_frame); @@ -1334,7 +1338,7 @@ static int enetc_xdp_frame_to_xdp_tx_swbd(struct enetc_bdr *tx_ring, n++; xdp_tx_swbd = &xdp_tx_arr[n]; } - +out: xdp_tx_arr[n - 1].is_eof = true; xdp_tx_arr[n - 1].xdp_frame = xdp_frame; @@ -1390,16 +1394,12 @@ static void enetc_map_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, { struct enetc_rx_swbd *rx_swbd = enetc_get_rx_buff(rx_ring, i, size); void *hard_start = page_address(rx_swbd->page) + rx_swbd->page_offset; - struct skb_shared_info *shinfo; /* To be used for XDP_TX */ rx_swbd->len = size; xdp_prepare_buff(xdp_buff, hard_start - rx_ring->buffer_offset, rx_ring->buffer_offset, size, false); - - shinfo = xdp_get_shared_info_from_buff(xdp_buff); - shinfo->nr_frags = 0; } static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, @@ -1407,7 +1407,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, { struct skb_shared_info *shinfo = xdp_get_shared_info_from_buff(xdp_buff); struct enetc_rx_swbd *rx_swbd = enetc_get_rx_buff(rx_ring, i, size); - skb_frag_t *frag = &shinfo->frags[shinfo->nr_frags]; + skb_frag_t *frag; /* To be used for XDP_TX */ rx_swbd->len = size; @@ -1415,6 +1415,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, if (!xdp_buff_has_frags(xdp_buff)) { xdp_buff_set_frags_flag(xdp_buff); shinfo->xdp_frags_size = size; + shinfo->nr_frags = 0; } else { shinfo->xdp_frags_size += size; } @@ -1422,6 +1423,7 @@ static void enetc_add_rx_buff_to_xdp(struct enetc_bdr *rx_ring, int i, if (page_is_pfmemalloc(rx_swbd->page)) xdp_buff_set_frag_pfmemalloc(xdp_buff); + frag = &shinfo->frags[shinfo->nr_frags]; skb_frag_off_set(frag, rx_swbd->page_offset); skb_frag_size_set(frag, size); __skb_frag_set_page(frag, rx_swbd->page);