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