Skip to contentSkip to conversation

Fix thunderx MTU with XDP

PATCH Superseded Matteo Croce 2 participants 5 messages Apr 8, 2019 – Apr 11, 2019

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Fix thunderx MTU with XDP

The thunderx driver can't use XDP with all MTU values.
This patches sets the right MTU values, and add a check to avoid setting a wrong value which will not function.

Matteo Croce (2):
net: thunderx: raise XDP MTU to 1508
net: thunderx: don't allow jumbo frames with XDP

 .../net/ethernet/cavium/thunder/nicvf_main.c  | 22 +++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
Signature · 1 line
2.21.0
#1 lore raw

PATCH v2 1/2 net: thunderx: raise XDP MTU to 1508

The thunderx driver splits frames bigger than 1530 bytes to multiple pages, making impossible to run an eBPF program on it. This leads to a maximum MTU of 1508 if QinQ is in use.

The thunderx driver forbids to load an eBPF program if the MTU is higher than 1500 bytes. Raise the limit to 1508 so it is possible to use L2 protocols which need some more headroom.

Fixes 05c773f52b96e ("net: thunderx: Add basic XDP support")
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +11 -2
index 28eac9056211..debc8c861c6b 100644
@@ -32,6 +32,13 @@
 #define DRV_NAME	"nicvf"
 #define DRV_VERSION	"1.0"
 
+/* NOTE: Packets bigger than 1530 are split across multiple pages and XDP needs
+ * the buffer to be contiguous. Allow XDP to be set up only if we don't exceed
+ * this value, keeping headroom for the 14 byte Ethernet header and two
+ * VLAN tags (for QinQ)
+ */
+#define MAX_XDP_MTU	(1530 - ETH_HLEN - VLAN_HLEN * 2)
+
 /* Supported devices */
 static const struct pci_device_id nicvf_id_table[] = {
 	{ PCI_DEVICE_SUB(PCI_VENDOR_ID_CAVIUM,
@@ -1830,8 +1837,10 @@ static int nicvf_xdp_setup(struct nicvf *nic, struct bpf_prog *prog)
 	bool bpf_attached = false;
 	int ret = 0;
 
-	/* For now just support only the usual MTU sized frames */
-	if (prog && (dev->mtu > 1500)) {
+	/* For now just support only the usual MTU sized frames,
+	 * plus some headroom for VLAN, QinQ.
+	 */
+	if (prog && dev->mtu > MAX_XDP_MTU) {
 		netdev_warn(dev, "Jumbo frames not yet supported with XDP, current MTU %d.\n",
 			    dev->mtu);
 		return -EOPNOTSUPP;
Signature · 1 line
2.21.0
#2 lore raw

PATCH v2 2/2 net: thunderx: don't allow jumbo frames with XDP

In reply to Matteo Croce

The thunderx driver forbids to load an eBPF program if the MTU is too high, but this can be circumvented by loading the eBPF, then raising the MTU.

Fix this by limiting the MTU if an eBPF program is already loaded.

Fixes 05c773f52b96e ("net: thunderx: Add basic XDP support")
---
 drivers/net/ethernet/cavium/thunder/nicvf_main.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/net/ethernet/cavium/thunder/nicvf_main.c +9 -0
index debc8c861c6b..a923a4daaa9e 100644
@@ -1589,6 +1589,15 @@ static int nicvf_change_mtu(struct net_device *netdev, int new_mtu)
 	struct nicvf *nic = netdev_priv(netdev);
 	int orig_mtu = netdev->mtu;
 
+	/* For now just support only the usual MTU sized frames,
+	 * plus some header for VLAN, QinQ.
+	 */
+	if (nic->xdp_prog && new_mtu > MAX_XDP_MTU) {
+		netdev_warn(dev, "Jumbo frames not yet supported with XDP, current MTU %d.\n",
+			    netdev->mtu);
+		return -EINVAL;
+	}
+
 	netdev->mtu = new_mtu;
 
 	if (!netif_running(netdev))
Signature · 1 line
2.21.0
maintainer
#3 lore raw
In reply to Matteo Croce

From: Matteo Croce <[email protected]>
Date: Mon, 8 Apr 2019 23:06:45 +0200

Quoted 3 lines

The thunderx driver can't use XDP with all MTU values.
This patches sets the right MTU values, and add a check to avoid setting a wrong value which will not function.

Series applied and queued up for -stable.

maintainer
#4 lore raw

From: David Miller <[email protected]>
Date: Wed, 10 Apr 2019 19:35:16 -0700 (PDT)

Quoted 8 lines

From: Matteo Croce <[email protected]>
Date: Mon, 8 Apr 2019 23:06:45 +0200

Quoted 3 lines

The thunderx driver can't use XDP with all MTU values.
This patches sets the right MTU values, and add a check to avoid setting a wrong value which will not function.

Series applied and queued up for -stable.

Actually, reverted, -ENOCOMPILE:

drivers/net/ethernet/cavium/thunder/nicvf_main.c: In function ‘nicvf_change_mtu’:
drivers/net/ethernet/cavium/thunder/nicvf_main.c:1596:15: error: ‘dev’ undeclared (first use in this function); did you mean ‘cdev’?
netdev_warn(dev, "Jumbo frames not yet supported with XDP, current MTU %d.\n",

               ^~~
               cdev

drivers/net/ethernet/cavium/thunder/nicvf_main.c:1596:15: note: each undeclared identifier is reported only once for each function it appears in