* [PATCH net v3] pppox: drop queued packets on channel handoff
@ 2026-12-01 17:34 Nicolas Dichtel
2026-12-05 17:54 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Dichtel @ 2026-12-01 17:34 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski, Paolo Abeni, Eric Dumazet,
Willem de Bruijn, Andrew Lunn, James Chapman, Simon Horman,
Qingfang Deng
Cc: netdev, Nicolas Dichtel, stable
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v3] pppox: drop queued packets on channel handoff
2026-12-01 17:34 [PATCH net v3] pppox: drop queued packets on channel handoff Nicolas Dichtel
@ 2026-12-05 17:54 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 17:54 UTC (permalink / raw)
To: nicolas.dichtel
Cc: davem, kuba, pabeni, edumazet, willemb, andrew+netdev, jchapman,
horms, qingfang.deng, netdev, stable
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] A deferred purge callback from an earlier binding can empty
the receive queue of a later, still-readable PPPoE connection.
- [Medium] `po->purge_pending` is the only signal that `po->purge_rcu`
may be passed to call_rcu() again, but it is published without…
--
pppox: drop queued packets on channel handoff
This patch removes the synchronize_net() and the drain to ppp_input()
from PPPIOCGCHAN. In their place it takes a socket reference and queues
an RCU callback that purges the receive queue. If a purge from an
earlier binding is still pending, PPPIOCGCHAN waits for a grace period
and purges synchronously, and pppox_exit() now calls rcu_barrier().
> diff --git a/drivers/net/ppp/pppox.c b/drivers/net/ppp/pppox.c
> index a6f72c813bef9..605054013a34d 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);
[Severity: Medium]
Can this callback drop frames that belong to a later connection on the
same socket?
pppox_purge_rcv_queue() empties sk_receive_queue every time it runs. It
does not check whether the socket is still in the binding that queued
the callback. Consider this sequence:
1. connect(sid=A), then PPPIOCGCHAN. pppox_ioctl() sets PPPOX_BOUND and
purge_pending = true, then calls call_rcu().
2. Before the callback runs, userspace calls connect(sid=0) and then
connect(sid=B). A PADT or flush that sets PPPOX_DEAD before the
reconnect works too. pppoe_connect() then does:
drivers/net/ppp/pppoe.c:pppoe_connect() {
...
if (stage_session(po->pppoe_pa.sid)) {
pppox_unbind_sock(sk);
...
synchronize_net();
...
sk->sk_state = PPPOX_NONE;
}
...
sk->sk_state = PPPOX_CONNECTED;
...
}
pppoe_connect() never touches purge_rcu or purge_pending. Its
synchronize_net() also does not wait for callbacks queued earlier to
run. With CONFIG_RCU_LAZY, call_rcu() can wait several seconds before
starting the grace period.
3. The new session is CONNECTED but not BOUND, so pppoe_rcv_core()
queues its frames with sock_queue_rcv_skb(). pppoe_recvmsg() only
returns -EIO for BOUND sockets, so userspace can read these frames.
4. The stale callback then runs and drops the new session's frames.
The purge_pending branch in pppox_ioctl() only helps when PPPIOCGCHAN
is issued a second time. It does nothing for the window between the
reconnect and the rebind.
The new comment says the purge is meant to "drop the packets queued
before the handoff". The commit message only describes the case where
the socket is "reconnected and bound again within a grace period".
Before this patch, the drain ran synchronously in the same PPPIOCGCHAN
that set PPPOX_BOUND, so it could not reach a later connection. Is it
intended that a pending purge can now empty the queue of a reconnected,
still readable session?
> + WRITE_ONCE(po->purge_pending, false);
[Severity: Medium]
Is purge_pending ordered strongly enough to make reusing purge_rcu
safe?
rcu_do_batch() clears the callback pointer just before calling the
callback:
kernel/rcu/tree.c:rcu_do_batch() {
...
f = rhp->func;
debug_rcu_head_callback(rhp);
WRITE_ONCE(rhp->func, (rcu_callback_t)0L);
f(rhp);
...
}
When the queue is empty, skb_queue_purge() in pppox_purge_rcv_queue()
returns with no barrier at all. When it is not empty, the spin_lock and
spin_unlock pair does not order an earlier store before a later one. So
the func = 0 store and the purge_pending = false store are unordered.
The callback does not take lock_sock(). That means the socket lock held
in pppox_ioctl() does not serialize against it. On another CPU, a
PPPIOCGCHAN on a reconnected socket can run:
if (READ_ONCE(po->purge_pending)) {
...
} else {
WRITE_ONCE(po->purge_pending, true);
sock_hold(sk);
call_rcu(&po->purge_rcu, pppox_purge_rcv_queue);
}
call_rcu() then writes head->func with a plain store in
rcu_do_enqueue().
On weakly ordered architectures such as arm64 or POWER, can the
func = 0 store from rcu_do_batch() become visible after the new
head->func store? That would leave a queued rcu_head with a NULL func,
and the next rcu_do_batch() would call it.
Hitting this needs a PPPIOCGCHAN, a reconnect through pppoe_connect(),
and a second PPPIOCGCHAN that races with the running callback on
another CPU. It cannot happen on x86.
Would one of these close the race?
- smp_store_release() in the callback paired with smp_load_acquire()
in pppox_ioctl()
- test_and_set_bit_lock() paired with clear_bit_unlock()
> + sock_put(sk);
> +}
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201173520.3359805-1-nicolas.dichtel%406wind.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 17:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 17:34 [PATCH net v3] pppox: drop queued packets on channel handoff Nicolas Dichtel
2026-12-05 17:54 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox