netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Camelia Groza <camelia.groza@nxp.com>
To: kuba@kernel.org, brouer@redhat.com, saeed@kernel.org,
	davem@davemloft.net
Cc: madalin.bucur@oss.nxp.com, ioana.ciornei@nxp.com,
	netdev@vger.kernel.org, Camelia Groza <camelia.groza@nxp.com>
Subject: [PATCH net-next v2 3/7] dpaa_eth: limit the possible MTU range when XDP is enabled
Date: Mon, 16 Nov 2020 16:42:29 +0200	[thread overview]
Message-ID: <b7a7b94112989269463c61c93deb82a9b791b7c9.1605535745.git.camelia.groza@nxp.com> (raw)
In-Reply-To: <cover.1605535745.git.camelia.groza@nxp.com>
In-Reply-To: <cover.1605535745.git.camelia.groza@nxp.com>

Implement the ndo_change_mtu callback to prevent users from setting an
MTU that would permit processing of S/G frames. The maximum MTU size
is dependent on the buffer size.

Signed-off-by: Camelia Groza <camelia.groza@nxp.com>
---
 drivers/net/ethernet/freescale/dpaa/dpaa_eth.c | 32 ++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
index 6b9ca60..5da4f17 100644
--- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
+++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c
@@ -2746,6 +2746,34 @@ static int dpaa_eth_stop(struct net_device *net_dev)
 	return err;
 }
 
+static bool xdp_validate_mtu(struct dpaa_priv *priv, int mtu)
+{
+	int max_contig_data = priv->dpaa_bp->size - priv->rx_headroom;
+
+	/* We do not support S/G fragments when XDP is enabled.
+	 * Limit the MTU in relation to the buffer size.
+	 */
+	if (mtu + VLAN_ETH_HLEN + ETH_FCS_LEN > max_contig_data) {
+		dev_warn(priv->net_dev->dev.parent,
+			 "The maximum MTU for XDP is %d\n",
+			 max_contig_data - VLAN_ETH_HLEN - ETH_FCS_LEN);
+		return false;
+	}
+
+	return true;
+}
+
+static int dpaa_change_mtu(struct net_device *net_dev, int new_mtu)
+{
+	struct dpaa_priv *priv = netdev_priv(net_dev);
+
+	if (priv->xdp_prog && !xdp_validate_mtu(priv, new_mtu))
+		return -EINVAL;
+
+	net_dev->mtu = new_mtu;
+	return 0;
+}
+
 static int dpaa_setup_xdp(struct net_device *net_dev, struct bpf_prog *prog)
 {
 	struct dpaa_priv *priv = netdev_priv(net_dev);
@@ -2754,8 +2782,7 @@ static int dpaa_setup_xdp(struct net_device *net_dev, struct bpf_prog *prog)
 	int err;
 
 	/* S/G fragments are not supported in XDP-mode */
-	if (prog && (priv->dpaa_bp->raw_size <
-	    net_dev->mtu + VLAN_ETH_HLEN + ETH_FCS_LEN))
+	if (prog && !xdp_validate_mtu(priv, net_dev->mtu))
 		return -EINVAL;
 
 	up = netif_running(net_dev);
@@ -2852,6 +2879,7 @@ static int dpaa_ioctl(struct net_device *net_dev, struct ifreq *rq, int cmd)
 	.ndo_set_rx_mode = dpaa_set_rx_mode,
 	.ndo_do_ioctl = dpaa_ioctl,
 	.ndo_setup_tc = dpaa_setup_tc,
+	.ndo_change_mtu = dpaa_change_mtu,
 	.ndo_bpf = dpaa_xdp,
 };
 
-- 
1.9.1


  parent reply	other threads:[~2020-11-16 14:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-16 14:42 [PATCH net-next v2 0/7] dpaa_eth: add XDP support Camelia Groza
2020-11-16 14:42 ` [PATCH net-next v2 1/7] dpaa_eth: add struct for software backpointers Camelia Groza
2020-11-16 14:42 ` [PATCH net-next v2 2/7] dpaa_eth: add basic XDP support Camelia Groza
2020-11-19  0:21   ` Jakub Kicinski
2020-11-19 13:50     ` Camelia Alexandra Groza
2020-11-16 14:42 ` Camelia Groza [this message]
2020-11-16 14:42 ` [PATCH net-next v2 4/7] dpaa_eth: add XDP_TX support Camelia Groza
2020-11-16 14:42 ` [PATCH net-next v2 5/7] dpaa_eth: add XDP_REDIRECT support Camelia Groza
2020-11-16 14:42 ` [PATCH net-next v2 6/7] dpaa_eth: rename current skb A050385 erratum workaround Camelia Groza
2020-11-16 14:42 ` [PATCH net-next v2 7/7] dpaa_eth: implement the A050385 erratum workaround for XDP Camelia Groza
2020-11-16 15:39 ` [PATCH net-next v2 0/7] dpaa_eth: add XDP support Madalin Bucur (OSS)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b7a7b94112989269463c61c93deb82a9b791b7c9.1605535745.git.camelia.groza@nxp.com \
    --to=camelia.groza@nxp.com \
    --cc=brouer@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ioana.ciornei@nxp.com \
    --cc=kuba@kernel.org \
    --cc=madalin.bucur@oss.nxp.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeed@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).