🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25388

[PATCH net v3] pppox: drop queued packets on channel handoff

#25388
From: Nicolas Dichtel
Date: Tue, 01 Dec 2026 17:34
161 lines
16777 bytes
Commit 92c1bf630abf ("pppox: drain queued packets on channel handoff")
added a synchronize_net() call to PPPIOCGCHAN, so that the receive paths
that observed the old state finish queueing their packets before the queue
is drained.

PPPIOCGCHAN is issued once per session by PPP daemons, so each session
setup now waits for a full RCU grace period. With accel-ppp, the PPPoE
session setup rate drops from ~1100 to ~250 sessions per second, and the
latency of pppox_ioctl() goes from a few microseconds to 4-8 ms. L2TP is
affected as well: the setup rate of an LNS is more than halved.

The regression was triggered in CI testing by a PPPoE performance test
(accel-ppp server in a VM using ConnectX-6 VFs, bngblaster client) on an
unmodified kernel. It was validated by reverting 92c1bf630abf, which
restores the v7.2 setup rate, and by measuring the latency of pppox_ioctl()
while PPPoE sessions are being set up:

  bpftrace -e 'kprobe:pppox_ioctl { @s[tid] = nsecs }
    kretprobe:pppox_ioctl /@s[tid]/ {
      @us = hist((nsecs - @s[tid]) / 1000); delete(@s[tid]); }'

Waiting for a grace period only for the lockless receive paths is not an
option, as PPPoE is going to receive packets without serialization as well,
once its __sk_receive_skb() call is removed.

Purging the queue right away is not enough either: a receive path that
observed the old state can still queue packets after the purge. Instead,
defer the work to an RCU callback, so that PPPIOCGCHAN does not block: on
the PPPOX_BOUND transition, take a reference on the socket and queue an RCU
callback. Once the receive paths that observed the old state are done,
the callback purges the receive queue and releases the socket.

The queued packets are dropped rather than delivered to generic PPP, as
the callback runs in softirq context and cannot serialize with the
unregistration of the channel. These packets are early PPP control frames,
which the peer retransmits. Before the faulty commit, they were not
delivered either: they stayed in the queue until the socket was destroyed.

The rcu_head cannot be reused while a callback is pending. This can happen
if a PPPoE socket is reconnected and bound again within a grace period: in
that rare case, wait for the grace period and purge the queue
synchronously. Nothing is done when PPPIOCGCHAN is issued on an already
bound socket. pppox_exit() waits for the pending callbacks.

This fix was tested against the reproducer: the PPPoE setup rate goes
from ~250 to ~1020 sessions per second, and the L2TP (LNS) setup rate
from ~270 to ~650 sessions per second. The pppoe.sh and pppol2tp.sh
selftests also pass.

Fixes: 92c1bf630abf ("pppox: drain queued packets on channel handoff")
Cc: stable@vger.kernel.org
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---

v3:
  - defer the purge to an RCU callback (Qingfang)
  - do nothing when PPPIOCGCHAN is issued on an already bound socket
  - if the purge of a previous binding is still pending, wait for a grace
    period and purge the queue synchronously
  - wait for the pending callbacks in pppox_exit()
  - add the L2TP setup rates to the commit log

v2: https://lore.kernel.org/netdev/20261130101628.1560335-1-nicolas.dichtel@6wind.com/
  - drop the queued packets instead of waiting for a grace period
    only for lockless receive paths (Qingfang)
  - new subject, was "pppox: only wait for a grace period for lockless

v1: https://lore.kernel.org/netdev/20261127152822.2098330-1-nicolas.dichtel@6wind.com/

 drivers/net/ppp/pppox.c  | 37 +++++++++++++++++++++++++++----------
 include/linux/if_pppox.h |  3 +++
 2 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/drivers/net/ppp/pppox.c b/drivers/net/ppp/pppox.c
index a6f72c813bef..605054013a34 100644
--- a/drivers/net/ppp/pppox.c
+++ b/drivers/net/ppp/pppox.c
@@ -64,6 +64,17 @@ EXPORT_SYMBOL(register_pppox_proto);
 EXPORT_SYMBOL(unregister_pppox_proto);
 EXPORT_SYMBOL(pppox_unbind_sock);
 
+static void pppox_purge_rcv_queue(struct rcu_head *head)
+{
+	struct pppox_sock *po = container_of(head, struct pppox_sock,
+					     purge_rcu);
+	struct sock *sk = &po->sk;
+
+	skb_queue_purge(&sk->sk_receive_queue);
+	WRITE_ONCE(po->purge_pending, false);
+	sock_put(sk);
+}
+
 int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 {
 	struct sock *sk = sock->sk;
@@ -74,7 +85,6 @@ int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 
 	switch (cmd) {
 	case PPPIOCGCHAN: {
-		struct sk_buff *skb;
 		int index;
 
 		rc = -ENOTCONN;
@@ -91,17 +101,22 @@ int pppox_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
 		 * generic PPP; pppd then attaches the returned channel to
 		 * /dev/ppp.
 		 */
+		if (sk->sk_state & PPPOX_BOUND)
+			break;
 		sk->sk_state |= PPPOX_BOUND;
-		/* Let lockless receive paths finish queueing against the old
-		 * state.
+		/* A bound socket is no longer readable: drop the packets
+		 * queued before the handoff, once the receive paths that
+		 * observed the old state are done. Do not wait for them here:
+		 * this ioctl is issued for each session setup.
 		 */
-		synchronize_net();
-		/* Drain packets queued before the handoff because a bound
-		 * socket is no longer readable.
-		 */
-		while ((skb = skb_dequeue(&sk->sk_receive_queue))) {
-			skb_orphan(skb);
-			ppp_input(&po->chan, skb);
+		if (READ_ONCE(po->purge_pending)) {
+			/* The purge of a previous binding is still pending. */
+			synchronize_net();
+			skb_queue_purge(&sk->sk_receive_queue);
+		} else {
+			WRITE_ONCE(po->purge_pending, true);
+			sock_hold(sk);
+			call_rcu(&po->purge_rcu, pppox_purge_rcv_queue);
 		}
 		break;
 	}
@@ -161,6 +176,8 @@ static int __init pppox_init(void)
 static void __exit pppox_exit(void)
 {
 	sock_unregister(PF_PPPOX);
+	/* Wait for pending pppox_purge_rcv_queue() calls. */
+	rcu_barrier();
 }
 
 module_init(pppox_init);
diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
index 594d6dc3f4c9..f9e6c261b002 100644
--- a/include/linux/if_pppox.h
+++ b/include/linux/if_pppox.h
@@ -47,6 +47,9 @@ struct pppox_sock {
 		struct pptp_opt  pptp;
 	} proto;
 	__be16			num;
+	/* Purge of the receive queue after the PPPOX_BOUND transition */
+	struct rcu_head		purge_rcu;
+	bool			purge_pending;
 };
 #define pppoe_dev	proto.pppoe.dev
 #define pppoe_ifindex	proto.pppoe.ifindex
-- 
2.47.3
Technical Details
Message-ID: <20261201173520.3359805-1-nicolas.dichtel@6wind.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375247-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375247-linux-kernel-netdev=dewy.ru
From: nicolas.dichtel@6wind.com (Nicolas Dichtel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net v3] pppox: drop queued packets on channel handoff
Date: Tue,  1 Dec 2026 18:34:40 +0100
Organization: Usenet Network
Message-ID: <20261201173520.3359805-1-nicolas.dichtel@6wind.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1778853"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:EW/tLPDt2c+AKoaqrbErO3MJ8xo= sha256:nGWIiFg1uzQLAYrdsBj7GuyxPRNm5G1OAC6CSR0VxXQ=
	sha1:7X9B9IFRTDvs3qP8pfB/kSwHhCE= sha256:Uu7tnLzgNgE/nN13nE5BTZM2YnH9MDhg3F1Vgt4ii3c=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id F38B0117438; Tue,  1 Dec 2026 20:35:47 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=6wind.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id YQXhnfZ_gM2f;
	Tue,  1 Dec 2026 20:35:44 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-375247-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=6wind.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 9E78A117436; Tue,  1 Dec 2026 20:35:33 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id A957827B02; Tue,  1 Dec 2026 17:35:31 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1796146530;
	b=De8dptB2rYtp4M3iUyeVobZfoFxWmfmwt7gsLGo3LwWspllloL/9PWawTV21tG3o715s
	 rjxlHDQJjiIGEs7HBbK/Kz55H7MoggyYc38bh1g3Zkn/kaT6ybdy68PrEoDS594zbdm1U
	 chIft4fRYP8p2B14+QX/fjXsPsPFZhqyaNxYYNgbghNXqQais8NBJelI9XHL17p0v/vZM
	 FZb7Db6fNpDjXhYgg0ztbh49EGLD3HZm6PfhH69+VvUsx0D7EEkMW0EJC1IcBtnqwmiig
	 0x6n0u3Yiy/YA+jixD8HpS+QDTWNqdnpQIyoZtDtNCcB7jWONxECTvo2S/rmQOxUd5w==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796146530;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:X-Relaying-Domain:Received:From:To:Cc:Subject:Date:
	 Message-ID:X-Mailer:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=vkbdSmu+dQraZUo0QnE+FtMSYXYndybzNJM37bWuN9I=;
	b=AOubnj0PzXPlmqkGPGMZjMyHfHvf6vuegrwYWKgc62RHPYq1hT5NjXfRJXros5c0ANuc
	 yJEra8NQXqj0EaeSgxud+cYvLelnikwh2gONTQRAyukB4+AfdzTOQcUSlGWSG3qp3HSpU
	 srtPq15mVEeCoQGGoy61q8sq7VZIDY1kM2dMqg9kMBVakJ0iSlEwHB31rXlz2hnOShO5Q
	 MnDM0OZws/aQnnKUS07fc8K9ZdhXCozDL5U//WHWAtCGThmN33LiN5KZknbXi5BvpBWqm
	 CMtBtUb4LoeL5uOaOAqrFtElDbBnfe8b+3YCpOVMeUBHGEqfgxNYQQjEuL4sSskEnDQ==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=6wind.com header.i=@6wind.com header.a=rsa-sha256 header.s=google header.b=Ha9sa+aA;
	dmarc=pass header.from=6wind.com;
	spf=pass smtp.mailfrom=6wind.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 37241606A32D;
	Tue,  1 Dec 2026 17:35:30 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=6wind.com header.i=@6wind.com header.a=rsa-sha256 header.s=google header.b=Ha9sa+aA
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.100
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1796146529;
	b=U3nGUnY6D5J1CjC/PdrQz262JzBn4VZMLBsPedakZ09MJDR+oBebO07O/NLGdgt4NjQk
	 DNdtLldq1tMywhNwQ0N88KrTVxghfti1M7G5Bm5WXWOUGiNOK0r/mdGRSAafdzdvzShXw
	 60Im6CsfDEnqvuIvV7IMHUJ3Ozaf/9pxh2V5aK2HUaTyZchsFLSVrg+VrSTIHLStsVDm4
	 TpAY+2qyvK6sq2R+/ha+FZsHkwZuIiIjaz1BeyDcgeIA8x9t+1W+2eMl558UZZDaeDkem
	 C1UjXtCIdeqLESXG6plM/QJBEsUMj0vVtNPBCPpdx7t4yIyY982t66iheS6A84POIZA==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796146529;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:X-Relaying-Domain:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version:
	 Content-Transfer-Encoding;
	bh=vkbdSmu+dQraZUo0QnE+FtMSYXYndybzNJM37bWuN9I=;
	b=OandxiA6O3+n7sbSLfZ26Ex9znqZiKRWYh35Wd85X0P9EfLEfsqygNHi+bFUv0SutsmC
	 kMaFziuywYhFPYIwbOxjhPPgLpz0wjGKtPV7derVpfD9iuq6Sh7cvQlerGA8E2utl4m1k
	 aW+FdGnF2uqlmFHCwh6W3GSpxPF+HxW2lsf8xBK5LfZRjfb5NMnaEKDw4rlX8Uat+knfJ
	 0liZA6MuEIx5CWMGMFhrxlXUy0tQKuVOE/2q4TXtlq90X0SksvQTwlEzRgaf/auPV51h+
	 /5fj4Xr0ntCpG9RaniCL6Xo/m0IM8Bi5leD1Vt7DrPmwvO09+S1uZ8wm50QvEvmjTTg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=6wind.com;
	spf=pass smtp.mailfrom=6wind.com;
	dkim=pass header.d=6wind.com header.i=@6wind.com header.a=rsa-sha256 header.s=google header.b=Ha9sa+aA;
	arc=none smtp.remote-ip=209.85.128.100
X-Received: from mail-wm1-f100.google.com (mail-wm1-f100.google.com [209.85.128.100])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id E7CFA606A31A
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 17:35:28 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7CFA606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com
X-Received: by mail-wm1-f100.google.com with SMTP id 5b1f17b1804b1-4a68f888a41so11334725e9.0
        for <netdev@vger.kernel.org>; Tue, 01 Dec 2026 09:35:28 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=6wind.com; s=google; t=1796146527; x=1796751327; 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:content-type;
        bh=vkbdSmu+dQraZUo0QnE+FtMSYXYndybzNJM37bWuN9I=;
        b=Ha9sa+aARyWG4RwXUkLXZUngBDf98k+gY703un7UcnudoyJS6k/Bu+9HipUAHRced5
         gnozNqyRhVGBOhRFzqGD9502k/FuqFHak3deijrcbehadgIa+pXFoZz0uUgrkZZCS5Uq
         8c4alZRW+MLmVsWV5BVMcGjWDv/RzYiwW6ox7IbqWOlQlbkmxyr0ZZykH8H4/ST4d7VW
         0snJUwPRVbPH5R49pz1qakNLJkGBcp6dXHDdXzuyrgku/utTE+UK2bRg+wEN4p7OkY4G
         0YHIFvRpQ5CHSlm/1C9mVL21nFcWpk7pnNhC/3OvxLGjeyk3/xnqg9T9W/A6ir2Um8Et
         1Otg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1796146527; x=1796751327;
        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:content-type;
        bh=vkbdSmu+dQraZUo0QnE+FtMSYXYndybzNJM37bWuN9I=;
        b=nMhhYWIpjSegX4JKnlS8bPPwJ51b4anz/zV3ild9MzKsaoBkrkHYdDV2H7L+ZMGeRh
         M9+wwP/T6/wH9LlQSD7UNtfKPpDs5+rfA4d6IhzJyMlutZGsvO8xqdvcRvuxz7nvkaf9
         pwctJtkvZmHgFWdcf/5NE5A2aWOcJi9P3yIhCi2efTty1gTIlDGTklVzsV5UlrIoq+s7
         mm4s/lbvshn/QRMs9hAHmt+bqH1epJxJFQ2UO200jO6Pb5wNh/ixQkbmrhwrJJBZHtUL
         JfqXVIRD+AzohM5eGF3wphokR7SpfGPedZUfb65KxoAKTiGfaXBHM1CeyjDsLgmwsijg
         ILXw==
X-Gm-Message-State: APuU4Z8S3x1/Je5fUvjSflz9CYPaqRXkfcoGnUlQrYlAz6GEIydB7F1J
	E7TTz0sUnRMb4MUCADyK5fWbdT+DYD0v7etvpgnryyjxltlGTydzgLNHR3SnfiDE4DhIIO+yV8z
	sZeRhaUjK989XOGU4xsJlBK9kJUrj3Yl6TXne
X-Gm-Gg: AZFdTZfJWMqOnJ2W5i1uy7UauYpgvqqayUSU8fpv1IWJBNqHkD2wruCLS6+uviM7gMv
	rTIf/IuAloz+K1tjG62Wsl7RDcjeZDTWTF6ao/7C/tlbdGNhj32aiaXf3zBXH/8iD/8aSmcipoy
	AMe3oSol4K51C2IVoZ420vSSVkx+/E0zuSS27DT0De3QIPwvS+53PKf6VFumHw6QNtKLHtXxFj/
	XTcuu1OgsVoAeTvWydnFB3k+xJTrhdj0KcXwgDwIvZjz3++GPjB7ZckQ+iyMARjdEB3JMEIRAvM
	RlfuHJGQx46YVSoBZP+0kez2STgTJdLRXu71zHKFgP+yqK2LpAY1EDCTXOYMxLy9zhMObl338bG
	j6JUniPupr4EBPsjLLsgTgP3kUg==
X-Received: by 2002:a05:600c:8210:b0:4bb:7ad8:99f2 with SMTP id 5b1f17b1804b1-4bb88785da4mr695596895e9.0.1796146527161;
        Tue, 01 Dec 2026 09:35:27 -0800 (PST)
X-Received: from smtpservice.6wind.com ([185.13.181.2])
        by smtp-relay.gmail.com with UTF8SMTP id 5b1f17b1804b1-4bb8843da6esm134310045e9.2.2026.12.01.09.35.27;
        Tue, 01 Dec 2026 09:35:27 -0800 (PST)
X-Relaying-Domain: 6wind.com
X-Received: from localhost (bretzel.dev.6wind.com [10.17.1.57])
	by smtpservice.6wind.com (Postfix) with UTF8SMTP id 0622610D14;
	Tue,  1 Dec 2026 18:35:27 +0100 (CET)
X-Cc: netdev@vger.kernel.org,
	Nicolas Dichtel <nicolas.dichtel@6wind.com>,
	stable@vger.kernel.org
X-Mailer: git-send-email 2.47.3
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list