From nobody Sat Apr 18 10:43:27 2026 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C883A23E334 for ; Sat, 28 Feb 2026 03:23:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772249007; cv=none; b=J95hnb+KzWwYVlABzsxj/QWnAnLeBIdRK4KmfdeAXI5l0Im88kCksuELxMYT2Y/ZosxIXMDJjJciKSMLG0SZJMlkOMawJKy+VvR6y4FZG+pAENnZ1gH4vTRRhHNv1OlIu+pphUyOvd7ZjPH2qOmlJ/rSwPuPzk0PZbO+sM4QJiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772249007; c=relaxed/simple; bh=2VJAOsbOXN64VK52QrdpFYnvXwbZL9fJZhXNnjkZROU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=mPdc33Nf5HUTrmNjhCaTgmF6/15UkIO9EU2lUlJo9awx2RGyXXOrMfDAOretScUk3ofx+dczYHMOu5PjpwAAJWiGuzExkiV/4FLmThH/4rfaPXaQ8rokKa7kyqtYZ+g3OSLPYiUGTR2bROTTCLBl80jzym3K8X9eA8mOESoIi3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aqx+oLir; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aqx+oLir" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-b935ff845c8so322223566b.2 for ; Fri, 27 Feb 2026 19:23:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772249004; x=1772853804; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=S0ZchPbAREZAzkXthv+xzhxFLPbamh8n6hQVVuKvb3g=; b=aqx+oLirmtrf047cB/nsQNydvCa9ehfIZ5e07rBt6fA1TDKxq9SjxYYSy2CbojBupo UM31OsRTK/ZYmlaRT8sfhM97046NV3lD5oPIj+PKWjMlR9Jsut5c3gbD6VPzP/fUkpaG idHlPRYVCtnNp0K4bSct8qzOj6OG9rvPJjgOdgx06YId0NG2nnfJtgYDc0LJgE3t3NQ1 Nf2dPqVWdyJRyuoSfyQgE/Sl1nYpsW/fQ7GM4j7NsHMenUt/wREGdheCJSWcddUdJEBn u2reGIOvGZpUXFeDULeRQU9A8Rd7h8vurve6kW71fR8tiCB7mf2906fGQZAr2wGF1wCa Lh3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772249004; x=1772853804; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=S0ZchPbAREZAzkXthv+xzhxFLPbamh8n6hQVVuKvb3g=; b=afsvI2JbnvpvEgNB3XO0/cTPnBnw9Wa6f5P2c7Nh+vbtgGFpT269kdMhT9soopzmbn tG8oK4ZUTz5i25+P5/TFfaDRmURQZg+tOgrUsVMqOkhOOy3t3yV1426OgGpgKxtdlHoS lChHnW48XClARnwsM2+GpfS7CM8MlHSf0cllnTTcLtB9Cudpy+4mjWWW7nt1oiDenIMn mzWYpCtd4VGWDfVr4dtXFtz77gAvwIZRMu9vxFB7QgZQBnB6hhoND4r6zHT864G8Zq7d xzeAxwcrCNkgcNp3VONFkfdCGvIGhBsDcIA2MsBC8Y7L64nq17AbZWO9dO4yQ7H/UbjG 4ekQ== X-Forwarded-Encrypted: i=1; AJvYcCUbHVNPOoub9h/8d/evxAvH768tS7HppNCvhfMgmnL7wZT8+aAabYY+rjPlhJyGQkmX35zn3S1oxGf8nHA=@vger.kernel.org X-Gm-Message-State: AOJu0YwekWKuNen/Wo1koNyRaTAfu9TjupUmhtowD09iudAjH9uWy+re vGNy+P0pT85vyRtQr8/IE8MSVSVV2+4dp7bFQf9A8YX87m8FNQgnui/p X-Gm-Gg: ATEYQzx1finyQTek4YoOmajBuIwy6Ly+6aUrNcyb3xQxbuDAySeAaRN7ACBDU9DjjU6 +oA/l5q9e0ks2mvtYSCF2lOngZssuaBpBOajcb4DkFIRdSJl/j74D8Da5I6bpXBxV4oEAQu6s1S OxGLOijg95aMYWJPq46wiHx/ydSRsDcQrEpiyIA6VuJm6nR+W16qs0YYIesDTUnRYr1u4Bs2vP5 V7144GQm8uK7+pOwHZLHPcGHfXopVUprLri13a0gYZ11cp4mTN/h9GiJ9Z+G1afUM8q2Tu2wWiV II5M9wpFsIITDphqbI8wh0pMmeul5ZRx4udwnctq9/dzSPU3rO+FoYdLA5EVkTa2+1/Cbrk2QZr T0Cm+FrTppyt4IIktP9N4R0tfSkYewBs+suLAOTDQHLqgNmkPsuht45k1zJqiKb4itgQzjOOk X-Received: by 2002:a17:907:3d51:b0:b8f:96f3:de05 with SMTP id a640c23a62f3a-b93765878e0mr300835866b.60.1772249003792; Fri, 27 Feb 2026 19:23:23 -0800 (PST) Received: from gmail.com ([2a09:bac1:5520::20a:ca]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-b935ac70b01sm203031266b.23.2026.02.27.19.23.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Feb 2026 19:23:23 -0800 (PST) From: Qingfang Deng To: linux-ppp@vger.kernel.org, Michal Ostrowski , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Simon Horman , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Felix Fietkau Subject: [PATCH net-next v4] net: pppoe: implement GRO/GSO support Date: Sat, 28 Feb 2026 11:23:17 +0800 Message-ID: <20260228032317.146855-1-dqfext@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Felix Fietkau 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. Signed-off-by: Felix Fietkau Signed-off-by: Qingfang Deng --- v4: - fetch ppp proto without using tag_type - filter for session packets (type:1, ver:1, code:0) - constify some parameters v3: https://lore.kernel.org/netdev/20250811095734.71019-1-nbd@nbd.name/ - increase priority value - implement GSO support - use INDIRECT_CALL_INET - update pppoe length field - remove unnecessary network_offsets update drivers/net/ppp/pppoe.c | 168 +++++++++++++++++++++++++++++++++++++++- net/ipv4/af_inet.c | 2 + net/ipv6/ip6_offload.c | 2 + 3 files changed, 171 insertions(+), 1 deletion(-) diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c index 1ac61c273b28..920d9015b4b4 100644 --- a/drivers/net/ppp/pppoe.c +++ b/drivers/net/ppp/pppoe.c @@ -77,6 +77,7 @@ #include #include #include +#include =20 #include =20 @@ -403,7 +404,7 @@ static int pppoe_rcv(struct sk_buff *skb, struct net_de= vice *dev, if (skb->len < len) goto drop; =20 - if (pskb_trim_rcsum(skb, len)) + if (!skb_is_gso(skb) && pskb_trim_rcsum(skb, len)) goto drop; =20 ph =3D pppoe_hdr(skb); @@ -1097,6 +1098,169 @@ static struct pernet_operations pppoe_net_ops =3D { .size =3D sizeof(struct pppoe_net), }; =20 +static u16 +compare_pppoe_header(const struct pppoe_hdr *phdr, + const struct pppoe_hdr *phdr2) +{ + const __be16 proto =3D *(const __be16 *)(phdr + 1); + const __be16 proto2 =3D *(const __be16 *)(phdr2 + 1); + + return (__force u16)((phdr->sid ^ phdr2->sid) | (proto ^ proto2)); +} + +static __be16 pppoe_hdr_proto(const struct pppoe_hdr *phdr) +{ + const __be16 proto =3D *(const __be16 *)(phdr + 1); + + switch (proto) { + case cpu_to_be16(PPP_IP): + return cpu_to_be16(ETH_P_IP); + case cpu_to_be16(PPP_IPV6): + return cpu_to_be16(ETH_P_IPV6); + 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 =3D NULL; + struct sk_buff *p; + int flush =3D 1; + __be16 type; + + off_pppoe =3D skb_gro_offset(skb); + hlen =3D off_pppoe + sizeof(*phdr); + phdr =3D skb_gro_header(skb, hlen + 2, off_pppoe); + if (unlikely(!phdr)) + goto out; + + /* filter for session packets (type:1, ver:1, code:0) */ + if (*(const __be16 *)phdr !=3D cpu_to_be16(0x1100)) + goto out; + + /* ignore packets with padding or invalid length */ + if (skb_gro_len(skb) !=3D be16_to_cpu(phdr->length) + hlen) + goto out; + + type =3D pppoe_hdr_proto(phdr); + if (!type) + goto out; + + ptype =3D gro_find_receive_by_type(type); + if (!ptype) + goto out; + + flush =3D 0; + + list_for_each_entry(p, head, list) { + const struct pppoe_hdr *phdr2; + + if (!NAPI_GRO_CB(p)->same_flow) + continue; + + phdr2 =3D (const struct pppoe_hdr *)(p->data + off_pppoe); + if (compare_pppoe_header(phdr, phdr2)) + NAPI_GRO_CB(p)->same_flow =3D 0; + } + + skb_gro_pull(skb, sizeof(*phdr) + 2); + skb_gro_postpull_rcsum(skb, phdr, sizeof(*phdr) + 2); + + pp =3D 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 =3D (struct pppoe_hdr *)(skb->data + nhoff); + __be16 type =3D pppoe_hdr_proto(phdr); + struct packet_offload *ptype; + int len, err; + + ptype =3D gro_find_complete_by_type(type); + if (!ptype) + return -ENOENT; + + err =3D INDIRECT_CALL_INET(ptype->callbacks.gro_complete, + ipv6_gro_complete, inet_gro_complete, + skb, nhoff + sizeof(*phdr) + 2); + if (err) + return err; + + len =3D skb->len - (nhoff + sizeof(*phdr)); + phdr->length =3D cpu_to_be16(len); + + return 0; +} + +static struct sk_buff *pppoe_gso_segment(struct sk_buff *skb, + netdev_features_t features) +{ + unsigned int pppoe_hlen =3D sizeof(struct pppoe_hdr) + 2; + struct sk_buff *segs =3D ERR_PTR(-EINVAL); + u16 mac_offset =3D skb->mac_header; + struct packet_offload *ptype; + u16 mac_len =3D skb->mac_len; + struct pppoe_hdr *phdr; + __be16 orig_type, type; + int len, nhoff; + + skb_reset_network_header(skb); + nhoff =3D skb_network_header(skb) - skb_mac_header(skb); + + if (unlikely(!pskb_may_pull(skb, pppoe_hlen))) + goto out; + + phdr =3D (struct pppoe_hdr *)skb_network_header(skb); + type =3D pppoe_hdr_proto(phdr); + ptype =3D gro_find_complete_by_type(type); + if (!ptype) + goto out; + + orig_type =3D skb->protocol; + __skb_pull(skb, pppoe_hlen); + segs =3D 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 =3D segs; + do { + phdr =3D (struct pppoe_hdr *)(skb_mac_header(skb) + nhoff); + len =3D skb->len - (nhoff + sizeof(*phdr)); + phdr->length =3D cpu_to_be16(len); + skb->network_header =3D (u8 *)phdr - skb->head; + skb->protocol =3D orig_type; + skb_reset_mac_len(skb); + } while ((skb =3D skb->next)); + +out: + return segs; +} + +static struct packet_offload pppoe_packet_offload __read_mostly =3D { + .type =3D cpu_to_be16(ETH_P_PPP_SES), + .priority =3D 20, + .callbacks =3D { + .gro_receive =3D pppoe_gro_receive, + .gro_complete =3D pppoe_gro_complete, + .gso_segment =3D pppoe_gso_segment, + }, +}; + static int __init pppoe_init(void) { int err; @@ -1113,6 +1277,7 @@ static int __init pppoe_init(void) if (err) goto out_unregister_pppoe_proto; =20 + dev_add_offload(&pppoe_packet_offload); dev_add_pack(&pppoes_ptype); dev_add_pack(&pppoed_ptype); register_netdevice_notifier(&pppoe_notifier); @@ -1132,6 +1297,7 @@ static void __exit pppoe_exit(void) unregister_netdevice_notifier(&pppoe_notifier); dev_remove_pack(&pppoed_ptype); dev_remove_pack(&pppoes_ptype); + dev_remove_offload(&pppoe_packet_offload); unregister_pppox_proto(PX_PROTO_OE); proto_unregister(&pppoe_sk_proto); unregister_pernet_device(&pppoe_net_ops); diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 8036e76aa1e4..b98e0b180955 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c @@ -1537,6 +1537,7 @@ struct sk_buff *inet_gro_receive(struct list_head *he= ad, struct sk_buff *skb) =20 return pp; } +EXPORT_INDIRECT_CALLABLE(inet_gro_receive); =20 static struct sk_buff *ipip_gro_receive(struct list_head *head, struct sk_buff *skb) @@ -1622,6 +1623,7 @@ int inet_gro_complete(struct sk_buff *skb, int nhoff) out: return err; } +EXPORT_INDIRECT_CALLABLE(inet_gro_complete); =20 static int ipip_gro_complete(struct sk_buff *skb, int nhoff) { diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c index bd7f780e37a5..32ba4739cef9 100644 --- a/net/ipv6/ip6_offload.c +++ b/net/ipv6/ip6_offload.c @@ -297,6 +297,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *ipv6_gro_receiv= e(struct list_head *head, =20 return pp; } +EXPORT_INDIRECT_CALLABLE(ipv6_gro_receive); =20 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); =20 static int sit_gro_complete(struct sk_buff *skb, int nhoff) { --=20 2.43.0