From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.100 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== 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== 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 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 ; Tue, 1 Dec 2026 17:35:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E7CFA606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=6wind.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=6wind.com 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 Received: by mail-wm1-f100.google.com with SMTP id 5b1f17b1804b1-4a68f888a41so11334725e9.0 for ; Tue, 01 Dec 2026 09:35:28 -0800 (PST) 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) 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 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) From: Nicolas Dichtel To: "David S . Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet , Willem de Bruijn , Andrew Lunn , James Chapman , Simon Horman , Qingfang Deng Cc: netdev@vger.kernel.org, Nicolas Dichtel , stable@vger.kernel.org Subject: [PATCH net v3] pppox: drop queued packets on channel handoff Date: Tue, 1 Dec 2026 18:34:40 +0100 Message-ID: <20261201173520.3359805-1-nicolas.dichtel@6wind.com> X-Mailer: git-send-email 2.47.3 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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