Allow increasing the MTU over page boundaries on veth devices if the attached xdp program declares to support xdp fragments. Enable NETIF_F_ALL_TSO when the device is running in xdp mode. Signed-off-by: Lorenzo Bianconi <lorenzo@xxxxxxxxxx> --- drivers/net/veth.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/net/veth.c b/drivers/net/veth.c index 47b21b1d2fd9..2d6777aabef1 100644 --- a/drivers/net/veth.c +++ b/drivers/net/veth.c @@ -293,8 +293,7 @@ static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, /* return true if the specified skb has chances of GRO aggregation * Don't strive for accuracy, but try to avoid GRO overhead in the most * common scenarios. - * When XDP is enabled, all traffic is considered eligible, as the xmit - * device has TSO off. + * When XDP is enabled, all traffic is considered eligible. * When TSO is enabled on the xmit device, we are likely interested only * in UDP aggregation, explicitly check for that if the skb is suspected * - the sock_wfree destructor is used by UDP, ICMP and XDP sockets - @@ -302,11 +301,13 @@ static int veth_forward_skb(struct net_device *dev, struct sk_buff *skb, */ static bool veth_skb_is_eligible_for_gro(const struct net_device *dev, const struct net_device *rcv, + const struct veth_rq *rq, const struct sk_buff *skb) { - return !(dev->features & NETIF_F_ALL_TSO) || - (skb->destructor == sock_wfree && - rcv->features & (NETIF_F_GRO_FRAGLIST | NETIF_F_GRO_UDP_FWD)); + return rcu_access_pointer(rq->xdp_prog) || + !(dev->features & NETIF_F_ALL_TSO) || + (skb->destructor == sock_wfree && + rcv->features & (NETIF_F_GRO_FRAGLIST | NETIF_F_GRO_UDP_FWD)); } static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) @@ -335,7 +336,7 @@ static netdev_tx_t veth_xmit(struct sk_buff *skb, struct net_device *dev) * Don't bother with napi/GRO if the skb can't be aggregated */ use_napi = rcu_access_pointer(rq->napi) && - veth_skb_is_eligible_for_gro(dev, rcv, skb); + veth_skb_is_eligible_for_gro(dev, rcv, rq, skb); } skb_tx_timestamp(skb); @@ -1511,7 +1512,6 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, struct veth_priv *priv = netdev_priv(dev); struct bpf_prog *old_prog; struct net_device *peer; - unsigned int max_mtu; int err; old_prog = priv->_xdp_prog; @@ -1519,6 +1519,8 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, peer = rtnl_dereference(priv->peer); if (prog) { + unsigned int max_mtu; + if (!peer) { NL_SET_ERR_MSG_MOD(extack, "Cannot set XDP when peer is detached"); err = -ENOTCONN; @@ -1528,9 +1530,9 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, max_mtu = PAGE_SIZE - VETH_XDP_HEADROOM - peer->hard_header_len - SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); - if (peer->mtu > max_mtu) { - NL_SET_ERR_MSG_MOD(extack, "Peer MTU is too large to set XDP"); - err = -ERANGE; + if (!prog->aux->xdp_has_frags && peer->mtu > max_mtu) { + NL_SET_ERR_MSG_MOD(extack, "prog does not support XDP frags"); + err = -EOPNOTSUPP; goto err; } @@ -1548,10 +1550,8 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, } } - if (!old_prog) { - peer->hw_features &= ~NETIF_F_GSO_SOFTWARE; - peer->max_mtu = max_mtu; - } + if (!old_prog) + peer->hw_features &= ~NETIF_F_GSO_FRAGLIST; } if (old_prog) { @@ -1559,10 +1559,8 @@ static int veth_xdp_set(struct net_device *dev, struct bpf_prog *prog, if (dev->flags & IFF_UP) veth_disable_xdp(dev); - if (peer) { - peer->hw_features |= NETIF_F_GSO_SOFTWARE; - peer->max_mtu = ETH_MAX_MTU; - } + if (peer) + peer->hw_features |= NETIF_F_GSO_FRAGLIST; } bpf_prog_put(old_prog); } -- 2.35.1