net: pppoe: implement GRO/GSO support
Subsystems (6)
RFC PATCH v6 1/2 net: pppoe: implement GRO/GSO support
From: Felix Fietkau <[email protected]>
Only handles packets where the pppoe header length field matches the exact packet length. Significantly improves rx throughput.
When running NAT traffic through a MediaTek MT7621 devices from a host behind PPPoE to a host directly connected via ethernet, the TCP throughput that the device is able to handle improves from ~130 Mbit/s to ~630 Mbit/s, using fraglist GRO.
---
v6:
- avoid phdr->length field overflow
- restore skb_is_gso() check
- do not register GRO if INET=n
- do not check for PPP_IPV6 if IPV6=n
- tail call gro_complete
https://lore.kernel.org/netdev/[email protected]/
--- drivers/net/ppp/pppoe.c | 166 +++++++++++++++++++++++++++++++++++++++- net/ipv4/af_inet.c | 2 + net/ipv6/ip6_offload.c | 2 + 3 files changed, 169 insertions(+), 1 deletion(-)
drivers/net/ppp/pppoe.c +165 -1
@@ -77,6 +77,7 @@#include <net/net_namespace.h> #include <net/netns/generic.h> #include <net/sock.h> +#include <net/gro.h> #include <linux/uaccess.h>
@@ -403,7 +404,7 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_device *dev,if (skb->len < len) goto drop; -if (pskb_trim_rcsum (skb, len)) +if (!skb_is_gso (skb) &&pskb_trim_rcsum (skb, len)) goto drop; ph =pppoe_hdr (skb);
@@ -1097,6 +1098,165 @@ static struct pernet_operations pppoe_net_ops = { .size = sizeof(struct pppoe_net), }; +static u16 +compare_pppoe_header (const struct pppoe_hdr *phdr, +const struct pppoe_hdr *phdr2) +{ +__be16 proto = *(const __be16 *)(phdr +1 ); +__be16 proto2 = *(const __be16 *)(phdr2 +1 ); + +return (__force u16)((phdr->sid ^ phdr2->sid) | (proto ^ proto2)); +} + +static __be16 pppoe_hdr_proto (const struct pppoe_hdr *phdr) +{ +__be16 proto = *(const __be16 *)(phdr +1 ); + +switch (proto) { +case cpu_to_be16 (PPP_IP ): +return cpu_to_be16 (ETH_P_IP ); +#if IS_ENABLED (CONFIG_IPV6 ) +case cpu_to_be16 (PPP_IPV6 ): +return cpu_to_be16 (ETH_P_IPV6 ); +#endif +default : +return 0 ; + } +} + +static struct sk_buff *pppoe_gro_receive (struct list_head *head, +struct sk_buff *skb) +{ +const struct packet_offload *ptype; +unsigned int hlen, off_pppoe; +const struct pppoe_hdr *phdr; +struct sk_buff *pp =NULL ; +struct sk_buff *p; +int flush =1 ; +__be16 type; + + off_pppoe =skb_gro_offset (skb); + hlen = off_pppoe +PPPOE_SES_HLEN ; + phdr =skb_gro_header (skb, hlen, off_pppoe); +if (unlikely (!phdr)) + goto out; + +/* filter for session packets (type:1, ver:1, code:0) */ +if (*(const __be16 *)phdr !=cpu_to_be16 (0x1100 )) + goto out; + +/* ignore packets with padding or invalid length */ +if (skb_gro_len (skb) !=be16_to_cpu (phdr->length) +sizeof (*phdr)) + goto out; + + type =pppoe_hdr_proto (phdr); + ptype =gro_find_receive_by_type (type); +if (!ptype) + goto out; + + flush =0 ; + +list_for_each_entry (p, head, list) { +const struct pppoe_hdr *phdr2; + +if (!NAPI_GRO_CB (p)->same_flow) +continue ; + + phdr2 = (const struct pppoe_hdr *)(p->data + off_pppoe); +if (compare_pppoe_header (phdr, phdr2)) +NAPI_GRO_CB (p)->same_flow =0 ; + } + +skb_gro_pull (skb,PPPOE_SES_HLEN ); +skb_gro_postpull_rcsum (skb, phdr,PPPOE_SES_HLEN ); + + pp =indirect_call_gro_receive_inet (ptype->callbacks.gro_receive, + ipv6_gro_receive, inet_gro_receive, + head, skb); + +out: +skb_gro_flush_final (skb, pp, flush); + +return pp; +} + +static int pppoe_gro_complete (struct sk_buff *skb,int nhoff) +{ +struct pppoe_hdr *phdr = (struct pppoe_hdr *)(skb->data + nhoff); +__be16 type =pppoe_hdr_proto (phdr); +struct packet_offload *ptype; +unsigned int len; + + ptype =gro_find_complete_by_type (type); +if (!ptype) +return -ENOENT ; + + len = skb->len - (nhoff +sizeof (*phdr)); + len =min (len,0xFFFFU ); + phdr->length =cpu_to_be16 (len); + +return INDIRECT_CALL_INET (ptype->callbacks.gro_complete, + ipv6_gro_complete, inet_gro_complete, + skb, nhoff +PPPOE_SES_HLEN ); +} + +static struct sk_buff *pppoe_gso_segment (struct sk_buff *skb, +netdev_features_t features) +{ +unsigned int pppoe_hlen =sizeof (struct pppoe_hdr ) +2 ; +struct sk_buff *segs =ERR_PTR (-EINVAL ); +u16 mac_offset = skb->mac_header; +struct packet_offload *ptype; +u16 mac_len = skb->mac_len; +struct pppoe_hdr *phdr; +__be16 orig_type, type; +int len, nhoff; + +skb_reset_network_header (skb); + nhoff =skb_network_header (skb) -skb_mac_header (skb); + +if (unlikely (!pskb_may_pull (skb, pppoe_hlen))) + goto out; + + phdr = (struct pppoe_hdr *)skb_network_header (skb); + type =pppoe_hdr_proto (phdr); + ptype =gro_find_complete_by_type (type); +if (!ptype) + goto out; + + orig_type = skb->protocol; +__skb_pull (skb, pppoe_hlen); + segs = ptype->callbacks.gso_segment (skb, features); +if (IS_ERR_OR_NULL (segs)) { +skb_gso_error_unwind (skb, orig_type, pppoe_hlen, mac_offset, + mac_len); + goto out; + } + + skb = segs; +do { + phdr = (struct pppoe_hdr *)(skb_mac_header (skb) + nhoff); + len = skb->len - (nhoff +sizeof (*phdr)); + phdr->length =cpu_to_be16 (len); + skb->network_header = (u8 *)phdr - skb->head; + skb->protocol = orig_type; +skb_reset_mac_len (skb); + }while ((skb = skb->next)); + +out: +return segs; +} + +static struct packet_offload pppoe_packet_offload__read_mostly = { + .type =cpu_to_be16 (ETH_P_PPP_SES ), + .priority =20 , + .callbacks = { + .gro_receive = pppoe_gro_receive, + .gro_complete = pppoe_gro_complete, + .gso_segment = pppoe_gso_segment, + }, +}; +static int __init pppoe_init (void ) {int err;
@@ -1113,6 +1273,8 @@ static int __init pppoe_init(void)if (err) goto out_unregister_pppoe_proto; +if (IS_ENABLED (CONFIG_INET )) +dev_add_offload (&pppoe_packet_offload);dev_add_pack (&pppoes_ptype);dev_add_pack (&pppoed_ptype);register_netdevice_notifier (&pppoe_notifier);
@@ -1132,6 +1294,8 @@ static void __exit pppoe_exit(void)unregister_netdevice_notifier (&pppoe_notifier);dev_remove_pack (&pppoed_ptype);dev_remove_pack (&pppoes_ptype); +if (IS_ENABLED (CONFIG_INET )) +dev_remove_offload (&pppoe_packet_offload);unregister_pppox_proto (PX_PROTO_OE );proto_unregister (&pppoe_sk_proto);unregister_pernet_device (&pppoe_net_ops);
net/ipv4/af_inet.c +2 -0
@@ -1539,6 +1539,7 @@ struct sk_buff *inet_gro_receive(struct list_head *head, struct sk_buff *skb)return pp; } +EXPORT_INDIRECT_CALLABLE (inet_gro_receive);static struct sk_buff *ipip_gro_receive (struct list_head *head,struct sk_buff *skb)
@@ -1624,6 +1625,7 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff) out:return err; } +EXPORT_INDIRECT_CALLABLE (inet_gro_complete);static int ipip_gro_complete (struct sk_buff *skb,int nhoff) {
net/ipv6/ip6_offload.c +2 -0
@@ -297,6 +297,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receive(struct list_head *head,return pp; } +EXPORT_INDIRECT_CALLABLE (ipv6_gro_receive);static struct sk_buff *sit_ip6ip6_gro_receive (struct list_head *head,struct sk_buff *skb)
@@ -359,6 +360,7 @@ INDIRECT_CALLABLE_SCOPE int ipv6_gro_complete(struct sk_buff *skb, int nhoff) out:return err; } +EXPORT_INDIRECT_CALLABLE (ipv6_gro_complete);static int sit_gro_complete (struct sk_buff *skb,int nhoff) {
Signature · 1 line
2.43.0
RFC PATCH v6 2/2 selftests: net: test PPPoE packets in gro.sh
Add PPPoE test-cases to the GRO selftest.
---
v6: new patch
I'm not sure if I should include all the existing IPv4/v6 tests for PPPoE. There are tests that hardcode ETH_HLEN as the NH offset, which are meant to test the L3 protocol, not the underlying protocol, and changing all of them seems too invasive.
Comments welcome, thanks.
--- tools/testing/selftests/drivers/net/config | 2 + tools/testing/selftests/drivers/net/gro.py | 25 +++++- tools/testing/selftests/net/lib/gro.c | 97 ++++++++++++++++------ 3 files changed, 98 insertions(+), 26 deletions(-)
tools/testing/selftests/drivers/net/config +2 -0
@@ -7,4 +7,6 @@ CONFIG_NETCONSOLE=m CONFIG_NETCONSOLE_DYNAMIC=y CONFIG_NETCONSOLE_EXTENDED_LOG=y CONFIG_NETDEVSIM=m +CONFIG_PPP=y +CONFIG_PPPOE=y CONFIG_XDP_SOCKETS=y
tools/testing/selftests/drivers/net/gro.py +23 -2
@@ -186,8 +186,17 @@ def _run_gro_bin(cfg, test_name, protocol=None, num_flows=None, dmac = _resolve_dmac(cfg, ipver) - base_args = [ - f"--{protocol}", + if protocol.startswith("pppoe"): + base_args = [ + f"--ipv{protocol[-1]}", + "--pppoe", + ] + else: + base_args = [ + f"--{protocol}", + ] + + base_args += [ f"--dmac {dmac}", f"--smac {cfg.remote_dev['address']}", f"--daddr {cfg.addr_v[ipver]}",
@@ -322,6 +331,18 @@ def _gro_variants(): for test_name in ipv6_tests: yield mode, protocol, test_name + for mode in ["sw"]: + for protocol in ["pppoev4", "pppoev6"]: + for test_name in common_tests: + yield mode, protocol, test_name + + if protocol == "pppoev4": + for test_name in ipv4_tests: + yield mode, protocol, test_name + elif protocol == "pppoev6": + for test_name in ipv6_tests: + yield mode, protocol, test_name + @ksft_variants(_gro_variants()) def test(cfg, mode, protocol, test_name):
tools/testing/selftests/net/lib/gro.c +73 -24
248 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [RFC PATCH net-next v6 2/2] selftests: net: test PPPoE packets in gro.sh
Quoted 10 lines · Qingfang Deng
Add PPPoE test-cases to the GRO selftest.
Signed-off-by Qingfang Deng <[email protected]>---
v6: new patchI'm not sure if I should include all the existing IPv4/v6 tests for PPPoE. There are tests that hardcode
ETH_HLENas the NH offset, which are meant to test the L3 protocol, not the underlying protocol, and changing all of them seems too invasive.
Overall this change looks good to me. But indeed all the churn of
(pppoe ? PPPOE_SES_HLEN : 0)
is a bit annoying. Left a few representative snippets below. I think that could be avoided similar to MAX_HDR_LEN by having a global definition and using that everywhere. Still a lot of churn, but at least no repeated open-coded logic.
Also consider whether running all these tests again in PPPoE adds value, if not, then indeed trim the tests to those that truly add code coverage.
Quoted 18 lines
tools/testing/selftests/net/lib/gro.c +2
-2@@ -745,7 +777,7 @@ static void add_ipv4_ts_option(void *buf, void *optpkt)memcpy (optpkt + tcp_offset + optlen, buf + tcp_offset,sizeof (struct tcphdr ) +PAYLOAD_LEN ); - iph = (struct iphdr *)(optpkt +ETH_HLEN ); + iph = (struct iphdr *)(optpkt +ETH_HLEN + (pppoe ?PPPOE_SES_HLEN :0 )); iph->ihl =5 + (optlen /4 ); iph->tot_len =htons (ntohs (iph->tot_len) + optlen); iph->check =0 ;@@ -755,7 +787,7 @@ static void add_ipv4_ts_option(void *buf, void *optpkt)static void add_ipv6_exthdr (void *buf,void *optpkt,__u8 exthdr_type,char *ext_payload) {struct ipv6_opt_hdr *exthdr = (struct ipv6_opt_hdr *)(optpkt + tcp_offset); -struct ipv6hdr *iph = (struct ipv6hdr *)(optpkt +ETH_HLEN ); +struct ipv6hdr *iph = (struct ipv6hdr *)(optpkt +ETH_HLEN + (pppoe ?PPPOE_SES_HLEN :0 ));char *exthdr_payload_start = (char *)(exthdr +1 ); exthdr->hdrlen =0 ;
Paolo Abeni
maintainerdrivers/net/ppp/pppoe.c static struct pernet_operations pppoe_net_ops = { · line 1195
Quoted 13 lines · Qingfang Deng
drivers/net/ppp/pppoe.c +13
-0+static int pppoe_gro_complete (struct sk_buff *skb,int nhoff) +{ +struct pppoe_hdr *phdr = (struct pppoe_hdr *)(skb->data + nhoff); +__be16 type =pppoe_hdr_proto (phdr); +struct packet_offload *ptype; +unsigned int len; + + ptype =gro_find_complete_by_type (type); +if (!ptype) +return -ENOENT ; + + len = skb->len - (nhoff +sizeof (*phdr)); + len =min (len,0xFFFFU );
AFAICS, when the computed len is >= 64K, and the above min() will truncate it, later pppoe_rcv() will drop the packet.
I think you should prevent such case at GRO time, flushing the chain when it grows too big.
Quoted 36 lines
drivers/net/ppp/pppoe.c +36
-0+ phdr->length =cpu_to_be16 (len); + +return INDIRECT_CALL_INET (ptype->callbacks.gro_complete, + ipv6_gro_complete, inet_gro_complete, + skb, nhoff +PPPOE_SES_HLEN ); +} + +static struct sk_buff *pppoe_gso_segment (struct sk_buff *skb, +netdev_features_t features) +{ +unsigned int pppoe_hlen =sizeof (struct pppoe_hdr ) +2 ; +struct sk_buff *segs =ERR_PTR (-EINVAL ); +u16 mac_offset = skb->mac_header; +struct packet_offload *ptype; +u16 mac_len = skb->mac_len; +struct pppoe_hdr *phdr; +__be16 orig_type, type; +int len, nhoff; + +skb_reset_network_header (skb); + nhoff =skb_network_header (skb) -skb_mac_header (skb); + +if (unlikely (!pskb_may_pull (skb, pppoe_hlen))) + goto out; + + phdr = (struct pppoe_hdr *)skb_network_header (skb); + type =pppoe_hdr_proto (phdr); + ptype =gro_find_complete_by_type (type); +if (!ptype) + goto out; + + orig_type = skb->protocol; +__skb_pull (skb, pppoe_hlen); + segs = ptype->callbacks.gso_segment (skb, features); +if (IS_ERR_OR_NULL (segs)) { + skb_gso_error_unwind(skb, orig_type, pppoe_hlen, mac_offset,
drivers/net/ppp/pppoe.c static struct pernet_operations pppoe_net_ops = { · line 1241
Quoted 10 lines
drivers/net/ppp/pppoe.c +10
-0+ mac_len); + goto out; + } + + skb = segs; + do { + phdr = (struct pppoe_hdr *)(skb_mac_header(skb) + nhoff); + len = skb->len - (nhoff + sizeof(*phdr)); + phdr->length = cpu_to_be16(len); + skb->network_header = (u8 *)phdr - skb->head;
I understand is quite late for the following question, but... The network headers points to the pppoe hdr. Should it point to the actual IP hdr?
Why not? A comment in the code or in the commit message would be appreciated.
/P
Quoted 3 lines · Paolo Abeni
AFAICS, when the computed len is >= 64K, and the above
min()will truncate it, laterpppoe_rcv()will drop the packet.
pppoe_rcv() does _not_ drop such packets.
The drop condition is "skb->len < ntohs(ph->length)", not the other way around.
Quoted 7 lines
drivers/net/ppp/pppoe.c static struct pernet_operations pppoe_net_ops = { · line 1241
Quoted 6 lines
drivers/net/ppp/pppoe.c +6
-0+ skb = segs; + do { + phdr = (struct pppoe_hdr *)(skb_mac_header(skb) + nhoff); + len = skb->len - (nhoff + sizeof(*phdr)); + phdr->length = cpu_to_be16(len); + skb->network_header = (u8 *)phdr - skb->head;
Quoted 6 lines
I understand is quite late for the following question, but... The network headers points to the pppoe hdr. Should it point to the actual IP hdr?
Why not? A comment in the code or in the commit message would be appreciated.
I'm not sure about the GSO stuff. This code is carried over from Felix's v3 patch unmodified and I haven't noticed any issues. Maybe he has the answer.
FYI, Pablo Neira Ayuso is adding the "inline PPPoE GSO" to Netfilter
flowtable: https://lore.kernel.org/netfilter-devel/[email protected]/
to work around missing GSO support in PPPoE driver, prior to this
patch.
Hi Paolo,
Quoted 18 lines · Qingfang Deng
Quoted 3 lines · Paolo Abeni
AFAICS, when the computed len is >= 64K, and the above
min()will truncate it, laterpppoe_rcv()will drop the packet.
pppoe_rcv()does _not_ drop such packets.
The drop condition is "skb->len<ntohs(ph->length)", not the other way around.Quoted 10 lines
drivers/net/ppp/pppoe.c static struct pernet_operations pppoe_net_ops = { · line 1241
Quoted 6 lines
drivers/net/ppp/pppoe.c +6
-0+ skb = segs; + do { + phdr = (struct pppoe_hdr *)(skb_mac_header(skb) + nhoff); + len = skb->len - (nhoff + sizeof(*phdr)); + phdr->length = cpu_to_be16(len); + skb->network_header = (u8 *)phdr - skb->head;I understand is quite late for the following question, but... The network headers points to the pppoe hdr. Should it point to the actual IP hdr?
This is the same with double-tagged-vlan, the network header also points to the inner vlan in the skb payload. Changing this would require to revisit all users in the tree that are already assuming this.
Quoted 11 lines
Quoted 2 lines
Why not? A comment in the code or in the commit message would be appreciated.
I'm not sure about the GSO stuff. This code is carried over from Felix's v3 patch unmodified and I haven't noticed any issues. Maybe he has the answer.
FYI, Pablo Neira Ayuso is adding the "inline PPPoE GSO" to Netfilter
flowtable: https://lore.kernel.org/netfilter-devel/[email protected]/
to work around missing GSO support in PPPoE driver, prior to this
patch.
Paolo Abeni
maintainerQuoted 16 lines · Pablo Neira Ayuso
Quoted 15 lines · Qingfang Deng
Quoted 3 lines · Paolo Abeni
AFAICS, when the computed len is >= 64K, and the above
min()will truncate it, laterpppoe_rcv()will drop the packet.
pppoe_rcv()does _not_ drop such packets.
The drop condition is "skb->len<ntohs(ph->length)", not the other way around.Quoted 7 lines
Quoted 6 lines
drivers/net/ppp/pppoe.c +6
-0+ skb = segs; + do { + phdr = (struct pppoe_hdr *)(skb_mac_header(skb) + nhoff); + len = skb->len - (nhoff + sizeof(*phdr)); + phdr->length = cpu_to_be16(len); + skb->network_header = (u8 *)phdr - skb->head;
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
I understand is quite late for the following question, but... The network headers points to the pppoe hdr. Should it point to the actual IP hdr?
This is the same with double-tagged-vlan, the network header also points to the inner vlan in the skb payload. Changing this would require to revisit all users in the tree that are already assuming this.
Ah right, the relevant GRO stage is running on top of an ethernet device and the RX path there resets the NH just after the ethernet one.
I got lost in the relevant hooking.
This patch (and v7) LGTM, thanks.
Paolo