ppp: transmit data frames without the unit and channel locks
Subsystems (5)
cover ppp: transmit data frames without the unit and channel locks
Every data frame sent on a PPP unit takes ppp->wlock in ppp_xmit_process() and the channel's downl in ppp_push(), so CPUs that send on one unit at the same time go through the channel and the lower device one frame at a time. On a router that shapes its upload with cake_mq on an ifb in front of a PPPoE device, the CAKE instance of each CPU dequeues into that one ppp device.
Patch 1 sends a data frame straight to the channel when none of the work done under those locks applies, for a channel that opts in with a new lockless_xmit flag. Patch 2 sets the flag for PPPoE. Patch 3 adds a selftest that sends from every CPU at once and compares the PPP and Ethernet counters.
Measured on the bench: on a Xiaomi AX3600 (IPQ8074, four Cortex-A53) uploading over PPPoE with 8 TCP streams, shaped to 160 Mbit/s by cake_mq on ifb4pppoe-wan, the router's CPU time fell from 24.2 % to 21.0 % of 400 % with patches 1 and 2 on its 6.18 kernel (three interleaved pairs of 60 s runs, 23.8-24.8 % against 18.9-22.6 %), at the same goodput of 149.6 to 150.0 Mbit/s and the same latency under load.
Patch 1 relies on ppp_unregister_channel() clearing pch->chan only after ppp_disconnect_channel() has removed the channel from ppp->channels and waited for a grace period. A PPPIOCDISCONN running at the same time lets the unregister skip that wait today; "ppp: serialize channel operations with unregister" closes that window:
https://lore.kernel.org/netdev/[email protected]/
In a 4-CPU KVM guest, pppoe.sh and ppp_async.sh pass in five runs on a KASAN and lockdep kernel with the series, and two rounds of stopping the client pppd while one TCP and one UDP sender per CPU transmit, then reconnecting, end without a report.
I used Claude (Anthropic) to help write these patches.
Julius Bairaktaris (3):
ppp: transmit data frames without the unit and channel locks
pppoe: transmit without the PPP channel lock
selftests: net: ppp: send on PPPoE from every CPU at once
drivers/net/ppp/ppp_generic.c | 85 ++++++++++++++++++++++-- drivers/net/ppp/pppoe.c | 7 +- include/linux/ppp_channel.h | 1 + tools/testing/selftests/net/ppp/config | 4 ++ tools/testing/selftests/net/ppp/pppoe.sh | 83 +++++++++++++++++++++++ 5 files changed, 170 insertions(+), 10 deletions(-)
base-commit: f89726ffabef1b08c52e6163b7ab94b0d5f15503
Signature · 1 line
2.53.0
PATCH 1/3 ppp: transmit data frames without the unit and channel locks
ppp_xmit_process() takes ppp->wlock and ppp_push() takes the channel's downl for every frame, so CPUs that transmit on one PPP unit at the same time run the channel's xmit and the lower device's transmit path one frame at a time. The device is already LLTX and, on a direct_xmit channel, IFF_NO_QUEUE, so these two locks are the only serialisation left.
Send a data frame straight to the channel when none of the work done under those locks applies: no multilink, no transmit compressor, no VJ compression of the frame, no demand loopback, no filter and no backlog on ppp->file.xq. A channel opts in with the new lockless_xmit flag, which promises that its start_xmit can run concurrently and accepts every frame. The channel is looked up under RCU, and ppp_disconnect_channel() already waits for a grace period after it removes the channel from ppp->channels. ppp_set_compress() now also waits for one after it installs the first transmit compressor, so no frame bypasses compression once CCP has started it. Control protocol frames (protocol 0x8000 and above) keep the locked path, and last_xmit is only written when jiffies has changed.
--- drivers/net/ppp/ppp_generic.c | 85 ++++++++++++++++++++++++++++++++--- include/linux/ppp_channel.h | 1 + 2 files changed, 79 insertions(+), 7 deletions(-)
drivers/net/ppp/ppp_generic.c +78 -7
@@ -823,7 +823,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)if (!(ppp->flags &SC_MULTILINK ) && (val &SC_MULTILINK )) ppp->nextseq =0 ;#endif - ppp->flags = val &SC_FLAG_BITS ; +WRITE_ONCE (ppp->flags, val &SC_FLAG_BITS );ppp_unlock (ppp);if (cflags &SC_CCP_OPEN )ppp_ccp_closed (ppp);
@@ -943,7 +943,7 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)ppp_lock (ppp);if (*which)bpf_prog_destroy (*which); - *which = filter; +WRITE_ONCE (*which, filter);ppp_unlock (ppp); err =0 ;break ;
@@ -1009,7 +1009,7 @@ static long ppp_compat_ioctl(struct file *file, unsigned int cmd, unsigned longppp_lock (ppp);if (*which)bpf_prog_destroy (*which); - *which = filter; +WRITE_ONCE (*which, filter);ppp_unlock (ppp); err =0 ;break ;
@@ -1564,7 +1564,7 @@ static void ppp_dev_uninit(struct net_device *dev)struct ppp_net *pn =ppp_pernet (ppp->ppp_net);ppp_lock (ppp); - ppp->closing =1 ; +WRITE_ONCE (ppp->closing,1 );ppp_unlock (ppp);mutex_lock (&pn->all_ppp_mutex);
@@ -1660,8 +1660,73 @@ static void ppp_xmit_flush(struct ppp *ppp)netif_wake_queue (netdev_from_priv (ppp)); } +/* +* Send a data frame straight to the channel, without ppp->wlock and +* pch->downl, when none of the work done under those locks applies: +* no multilink, transmit compressor, VJ compression of this frame, +* demand loopback, filters or transmit backlog, and a channel whose +* start_xmit may run concurrently. +* +* A frame that saw the old flags of a concurrent PPPIOCSFLAGS is sent +* as if it had been sent just before the update; none of these frames +* touches VJ or multilink state. Compression cannot start before +* ppp_set_compress() has installed a compressor and waited for a grace +* period, so no frame bypasses a running compressor. The +* channel stays registered until ppp_disconnect_channel() has removed +* it from ppp->channels and waited for a grace period. +* +* Returns true if the frame was consumed. +*/ +static bool ppp_xmit_lockless (struct ppp *ppp,struct sk_buff *skb) +{ +struct net_device *dev =netdev_from_priv (ppp); +unsigned int flags =READ_ONCE (ppp->flags); +unsigned long now = jiffies; +int proto =PPP_PROTO (skb); +struct ppp_channel *chan; +struct channel *pch; +bool ret = false; + +if (proto >=0x8000 || + (flags & (SC_MULTILINK |SC_LOOP_TRAFFIC )) || + (proto ==PPP_IP && (flags &SC_COMP_TCP )) || +READ_ONCE (ppp->xc_state) ||READ_ONCE (ppp->closing) || + !skb_queue_empty_lockless (&ppp->file.xq)) +return false; +#ifdef CONFIG_PPP_FILTER +if (READ_ONCE (ppp->pass_filter) ||READ_ONCE (ppp->active_filter)) +return false; +#endif /* CONFIG_PPP_FILTER */ + +rcu_read_lock (); + pch = list_first_or_null_rcu(&ppp->channels, struct channel, clist); +if (!pch) + goto out; + chan = pch->chan; +if (!chan->lockless_xmit) + goto out; + + skb->dev = dev; +/* Do not dirty a cache line shared by all CPUs for every frame. */ +if (READ_ONCE (ppp->last_xmit) != now) +WRITE_ONCE (ppp->last_xmit, now); +dev_sw_netstats_tx_add (dev,1 , skb->len -PPP_PROTO_LEN ); + +if (unlikely (!chan->direct_xmit &&skb_linearize (skb))) +kfree_skb (skb); +else if (WARN_ON_ONCE (!chan->ops->start_xmit (chan, skb))) +kfree_skb (skb); + ret = true; +out: +rcu_read_unlock (); +return ret; +} +static void __ppp_xmit_process (struct ppp *ppp,struct sk_buff *skb) { +if (ppp_xmit_lockless (ppp, skb)) +return ; +ppp_xmit_lock (ppp);if (unlikely (ppp->closing)) {kfree_skb (skb);
@@ -3153,11 +3218,17 @@ ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data) ocomp = ppp->xcomp; ostate = ppp->xc_state; ppp->xcomp = cp; - ppp->xc_state = state; +WRITE_ONCE (ppp->xc_state, state);ppp_xmit_unlock (ppp);if (ostate) { ocomp->comp_free (ostate);module_put (ocomp->owner); + }else { +/* Compression can start with the next CCP +* frame from pppd; let lockless senders that +* saw no compressor finish first. +*/ +synchronize_net (); } err =0 ; }else
@@ -3285,11 +3356,11 @@ ppp_ccp_closed(struct ppp *ppp)struct compressor *xcomp, *rcomp;ppp_lock (ppp); - ppp->flags &= ~(SC_CCP_OPEN |SC_CCP_UP ); +WRITE_ONCE (ppp->flags, ppp->flags & ~(SC_CCP_OPEN |SC_CCP_UP )); ppp->xstate =0 ; xcomp = ppp->xcomp; xstate = ppp->xc_state; - ppp->xc_state =NULL ; +WRITE_ONCE (ppp->xc_state,NULL ); ppp->rstate =0 ; rcomp = ppp->rcomp; rstate = ppp->rc_state;
include/linux/ppp_channel.h +1 -0
@@ -44,6 +44,7 @@ struct ppp_channel {int speed;/* transfer rate (bytes/second) */ bool direct_xmit;/* no qdisc, xmit directly */ bool xmit_offload;/* accepts GSO and CHECKSUM_PARTIAL skbs */ +bool lockless_xmit;/* concurrent start_xmit, never 0 */ };#ifdef __KERNEL__
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 3
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).
- [High] ppp: race with ppp_unregister_channel() causes NULL deref and UAF in ppp_xmit_lockless()
- [Low] Baseline decision: false positive, resolved later in the series.
- [Low] When ppp_set_compress() (drivers/net/ppp/ppp_generic.c) installs a transmit compressor while ostate is NULL, it now always…
- [Low] The channel API documentation was not updated for the new lockless_xmit contract, and this is still true at the end of the…
--
ppp: transmit data frames without the unit and channel locks
This adds ppp_xmit_lockless(). It sends data frames straight to the first channel under RCU, without ppp->wlock and pch->downl, as long as no multilink, compression, VJ, loopback, filter or backlog work applies. Channels opt in with a new lockless_xmit flag, and ppp_set_compress() now waits for a grace period after it installs the first transmit compressor.
Quoted 4 lines
drivers/net/ppp/ppp_generic.c +0
-0
[ ... ]
Quoted 1 line
drivers/net/ppp/ppp_generic.c +0
-0@@ -1660,8 +1660,73 @@ static void ppp_xmit_flush(struct ppp *ppp)
[ ... ]
Quoted 2 lines
drivers/net/ppp/ppp_generic.c +2
-0+static bool ppp_xmit_lockless (struct ppp *ppp,struct sk_buff *skb) +{
[ ... ]
Quoted 8 lines
drivers/net/ppp/ppp_generic.c +8
-0+rcu_read_lock (); + pch = list_first_or_null_rcu(&ppp->channels, struct channel, clist); +if (!pch) + goto out; + chan = pch->chan; +if (!chan->lockless_xmit) + goto out; +
drivers/net/ppp/ppp_generic.c static void ppp_xmit_flush(struct ppp *ppp) · line 1718
Quoted 10 lines
drivers/net/ppp/ppp_generic.c +10
-0+ skb->dev = dev; +/* Do not dirty a cache line shared by all CPUs for every frame. */ +if (READ_ONCE (ppp->last_xmit) != now) +WRITE_ONCE (ppp->last_xmit, now); +dev_sw_netstats_tx_add (dev,1 , skb->len -PPP_PROTO_LEN ); + +if (unlikely (!chan->direct_xmit &&skb_linearize (skb))) +kfree_skb (skb); +else if (WARN_ON_ONCE (!chan->ops->start_xmit (chan, skb))) +kfree_skb (skb);
[Severity: High]
Can ppp_xmit_lockless() see a channel that ppp_unregister_channel() has already torn down?
The lockless path reads pch->chan without downl and without a NULL check. It then dereferences chan->lockless_xmit and calls chan->ops->start_xmit(). The comment above the function says this is safe because the channel stays registered until ppp_disconnect_channel() has unlinked pch->clist and waited for a grace period. That only holds when the ppp_disconnect_channel() call made by ppp_unregister_channel() is the one that does the unlinking.
PPPIOCDISCONN calls ppp_disconnect_channel() with ppp_mutex held, but ppp_unregister_channel() calls it without ppp_mutex, so the two can run at the same time:
CPU0 (PPPIOCDISCONN) CPU1 (channel teardown)ppp_disconnect_channel()
pch->ppp = NULL under upl
ppp_unregister_channel()
ppp_disconnect_channel()
sees pch->ppp == NULL, returns
pch->chan = NULL under downl
returns, driver frees chan ppp_lock(ppp)
list_del_rcu(&pch->clist)
synchronize_net()
Until CPU0 reaches list_del_rcu(), pch is still the first entry on ppp->channels. A sender on another CPU can then load pch->chan as NULL and oops on chan->lockless_xmit. A sender that loaded chan just before CPU1 cleared it can still be inside chan->ops->start_xmit() after the driver has freed the channel. Nothing waits for a grace period between pch->chan = NULL and the driver freeing chan.
PPPIOCCONNECT has a similar window. If ppp_connect_channel() takes downl after ppp_unregister_channel() has returned from ppp_disconnect_channel() but before it clears pch->chan, it sees a non-NULL chan and links pch onto ppp->channels. pch->chan then goes to NULL while pch stays on the list.
The locked path survives both, because ppp_push() checks pch->chan for NULL under downl and drops the frame. The new path doesn't take downl, so the same races now end in a NULL deref or a use-after-free. They are reachable from ordinary teardown, for example a PPPoE PADT or a socket close racing with pppd's PPPIOCDISCONN. A process with CAP_NET_ADMIN in a user namespace can also trigger them on purpose.
Would it be enough to read pch->chan with READ_ONCE() and bail out on NULL here? ppp_unregister_channel() would then clear it with WRITE_ONCE() and wait for a grace period before it returns to the driver. Or would you rather serialise the two ppp_disconnect_channel() callers so that the existing synchronize_net() always runs before pch->chan is cleared? The second option would not cover the PPPIOCCONNECT case on its own.
[Severity: Low]
Should Documentation/networking/ppp_generic.rst and the start_xmit comment in include/linux/ppp_channel.h be updated for the new lockless_xmit contract?
ppp_generic.rst still lists this as a guarantee of the generic layer:
* The generic layer will not call the start_xmit() function for a channel while any thread is already executing in that function for that channel.
It also says start_xmit() may return 0 for flow control, and that the generic layer will retry the frame after ppp_output_wakeup(). The struct ppp_channel_ops comment for start_xmit still says "Returns 1 if it was accepted, 0 if not".
For channels that set lockless_xmit, ppp_xmit_lockless() calls start_xmit() from several CPUs at once without pch->downl. It can also run at the same time as ppp_push() and __ppp_channel_push(), which do hold downl. A 0 return here gives a WARN and drops the skb instead of queuing it.
The downl comment in struct channel says it protects chan and the file.xq dequeue. That is now incomplete, because pch->chan is read here under RCU only.
The only place the new rules are written down is the field comment "concurrent start_xmit, never 0". As far as I can tell, no Documentation/ files change anywhere in the series.
Quoted 5 lines
drivers/net/ppp/ppp_generic.c +5
-0+ ret = true; +out: +rcu_read_unlock (); +return ret; +}
[ ... ]
Quoted 7 lines
drivers/net/ppp/ppp_generic.c +1
-1@@ -3153,11 +3218,17 @@ ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data) ocomp = ppp->xcomp; ostate = ppp->xc_state; ppp->xcomp = cp; - ppp->xc_state = state; +WRITE_ONCE (ppp->xc_state, state);ppp_xmit_unlock (ppp);
drivers/net/ppp/ppp_generic.c ppp_set_compress(struct ppp *ppp, struct ppp_option_data *data) · line 3232
Quoted 10 lines
drivers/net/ppp/ppp_generic.c +6
-0if (ostate) { ocomp->comp_free (ostate);module_put (ocomp->owner); + }else { +/* Compression can start with the next CCP +* frame from pppd; let lockless senders that +* saw no compressor finish first. +*/ +synchronize_net (); }
[Severity: Low]
Does this need to hold up every PPP ioctl on the system for a full grace period?
ppp_ioctl() and ppp_compat_ioctl() call ppp_set_compress() with the global ppp_mutex held:
ppp_ioctl()
mutex_lock(&ppp_mutex);
...
ppp_set_compress()
synchronize_net();This happens on the first transmit PPPIOCSCOMPRESS of a session and again after every ppp_ccp_closed(). While it runs, all other PPP ioctls on every unit in every namespace wait behind it.
The wait only matters for units whose first channel sets lockless_xmit. pptp, l2tp, async and sync units pay for it too, even though they can never take the lockless path. Could the wait be skipped for those units?
PPPIOCDISCONN already calls synchronize_net() under ppp_mutex through ppp_disconnect_channel(), and this one runs once per CCP negotiation, so the cost is modest. The commit message mentions the wait. It doesn't say that the wait runs under the global mutex or that every unit pays for it.
[ ... ]
include/linux/ppp_channel.h struct ppp_channel { · line 47
Quoted 9 lines
include/linux/ppp_channel.h +1
-0@@ -44,6 +44,7 @@ struct ppp_channel {int speed;/* transfer rate (bytes/second) */ bool direct_xmit;/* no qdisc, xmit directly */ bool xmit_offload;/* accepts GSO and CHECKSUM_PARTIAL skbs */ +bool lockless_xmit;/* concurrent start_xmit, never 0 */
[Severity: Low]
Nothing in this patch sets lockless_xmit. With this patch applied on its own, ppp_xmit_lockless() always takes the goto out after this check:
if (!chan->lockless_xmit) goto out;
So the new path is never used.
The next patch in the series, "pppoe: transmit without the PPP channel lock", adds po->chan.lockless_xmit = true in pppoe_connect(), so this is resolved by the end of the series. pptp and l2tp intentionally don't opt in.
Would it help to say in the commit message that the first user comes in the next patch?
Quoted 3 lines
include/linux/ppp_channel.h +0
-0};#ifdef __KERNEL__
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129144319.1489366-1-julius%40bairaktaris.de
PATCH 2/3 pppoe: transmit without the PPP channel lock
In reply to Julius Bairaktarispppoe_xmit() reads the session's device, session ID and peer address, which are set before the channel is registered and stay valid until pppox_unbind_sock() has unregistered it, and hands the frame to dev_queue_xmit(). It never refuses a frame. Set lockless_xmit, so that ppp_generic calls it from several CPUs at once without the channel lock.
pppoe_release() and pppoe_unbind_sock_work() clear pppoe_dev before they unbind the socket, while frames may still be sent, so annotate those stores and load the pointer once with READ_ONCE().
With one iperf3 TCP stream per CPU over PPPoE on a veth in a 4-CPU KVM guest with lock_stat, ppp->wlock was contended in 805475 of 3245131 and in 530957 of 2517080 acquisitions before this series (two boots, three 10 s runs each). With it, a kprobe on ppp_push() counted no call while pppoe_xmit() sent 2684816 and 2316508 frames, and lock_stat lists no acquisition of ppp->wlock or of the channel's downl.
--- drivers/net/ppp/pppoe.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/net/ppp/pppoe.c +4 -3
@@ -400,7 +400,7 @@ static void pppoe_unbind_sock_work(struct work_struct *work)lock_sock (sk);if (po->pppoe_dev) {dev_put (po->pppoe_dev); - po->pppoe_dev =NULL ; +WRITE_ONCE (po->pppoe_dev,NULL ); }pppox_unbind_sock (sk);release_sock (sk);
@@ -523,7 +523,7 @@ static int pppoe_release(struct socket *sock)if (po->pppoe_dev) {dev_put (po->pppoe_dev); - po->pppoe_dev =NULL ; +WRITE_ONCE (po->pppoe_dev,NULL ); }pppox_unbind_sock (sk);
@@ -639,6 +639,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr po->chan.ops = &pppoe_chan_ops; po->chan.direct_xmit = true; po->chan.xmit_offload = true; + po->chan.lockless_xmit = true; error =ppp_register_net_channel (dev_net (dev), &po->chan);if (error) {
@@ -814,7 +815,7 @@ static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb) {struct sock *sk = chan->private;struct pppox_sock *po =pppox_sk (sk); -struct net_device *dev = po->pppoe_dev; +struct net_device *dev =READ_ONCE (po->pppoe_dev);struct pppoe_hdr *ph;int data_len = skb->len;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 3
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).
- [High] pppoe: premature unbind in ppp_unregister_channel() with lockless_xmit
- [Low] The commit message says pppoe_xmit() only reads fields that 'are set before the channel is registered and stay valid until…
- [Low] Documentation/networking/ppp_generic.rst still promises every channel (lines 236-238): 'The generic layer will not call the…
- [Low] The patch marks the stores that clear po->pppoe_dev with WRITE_ONCE(), in pppoe_release() (pppoe.c:526) and…
--
pppoe: transmit without the PPP channel lock
This patch sets lockless_xmit on PPPoE channels. With it, ppp_generic calls pppoe_xmit() from several CPUs at once without the channel lock. It also uses WRITE_ONCE() for the stores that clear po->pppoe_dev in pppoe_release() and pppoe_unbind_sock_work(), and READ_ONCE() for the load in pppoe_xmit().
Quoted 4 lines
pppoe_xmit()reads the session's device, session ID and peer address, which are set before the channel is registered and stay valid untilpppox_unbind_sock()has unregistered it, and hands the frame todev_queue_xmit().
[Severity: Low]
Is this accurate for the session ID? In pppoe_connect(), po->num is written only after the channel is registered and after PPPOX_CONNECTED is set:
drivers/net/ppp/pppoe.c:pppoe_connect() {
...
error = ppp_register_net_channel(dev_net(dev), &po->chan);
if (error) {
delete_item(pn, po);
goto err_put;
}
sk->sk_state = PPPOX_CONNECTED;
}
po->num = sp->sa_addr.pppoe.sid;
...
}pppoe_xmit() checks PPPOX_CONNECTED and then copies po->num into ph->sid without taking any lock.
pppoe_xmit() also reads sk->sk_state without a lock. That field is still written while the channel is registered: pppox_ioctl() handles PPPIOCGCHAN with sk->sk_state |= PPPOX_BOUND under lock_sock().
What seems to protect these fields is that pppd gets the channel index through PPPIOCGCHAN. That ioctl takes lock_sock(), so it runs after pppoe_connect() has called release_sock().
Only a CAP_NET_ADMIN process that guesses the channel index and attaches it during connect could see po->num == 0. The old downl lock never ordered against pppoe_connect() either, so this patch adds no new race.
Could the commit message state that invariant instead? Alternatively, pppoe_connect() could assign po->num before ppp_register_net_channel() so that the stated ordering holds.
Quoted 4 lines
drivers/net/ppp/pppoe.c +0
-0
[ ... ]
drivers/net/ppp/pppoe.c static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr · line 642
Quoted 5 lines
drivers/net/ppp/pppoe.c +1
-0@@ -639,6 +639,7 @@ static int pppoe_connect(struct socket *sock, struct sockaddr_unsized *uservaddr po->chan.ops = &pppoe_chan_ops; po->chan.direct_xmit = true; po->chan.xmit_offload = true; + po->chan.lockless_xmit = true;
[Severity: High]
Does ppp_unregister_channel() still wait for lockless senders in every case once this is set?
ppp_xmit_lockless() finds pch on ppp->channels under rcu_read_lock() only. It then loads pch->chan and calls chan->ops->start_xmit() without ppp->wlock or pch->downl. That is only safe if ppp_disconnect_channel() has done list_del_rcu(&pch->clist) and synchronize_net() before ppp_unregister_channel() sets pch->chan to NULL.
ppp_disconnect_channel() can be entered twice for the same channel, though:
- ppp_ioctl() handles PPPIOCDISCONN under ppp_mutex, without lock_sock().
- pppox_unbind_sock() calls ppp_unregister_channel() under lock_sock(), without ppp_mutex.
The first caller clears pch->ppp under pch->upl and drops upl. Only then does it take ppp_lock() for list_del_rcu() and sleep in synchronize_net(). A second caller that arrives in that window sees pch->ppp == NULL and returns -EINVAL at once.
Consider pppd issuing PPPIOCDISCONN while a PADT runs pppoe_unbind_sock_work(), or while pppoe_release() or pppoe_flush_dev() unbinds the socket. ppp_unregister_channel() can then set pch->chan to NULL under downl and return in two states: with pch still on ppp->channels, or with the grace period still pending.
A sender that already found pch then dereferences a NULL chan at the chan->lockless_xmit check in ppp_xmit_lockless(). A sender that is already inside pppoe_xmit() keeps using po->num, po->pppoe_pa.remote and the socket itself. It does so after pppox_unbind_sock() has returned, and possibly after pppoe_release() has dropped its reference with sock_put().
In the ppp_push() path, pch->downl covers this. ppp_push() holds downl across start_xmit(), and ppp_unregister_channel() takes downl before it clears pch->chan. The lockless path has nothing equivalent, and this patch is what routes PPPoE frames through it.
How would you like to close this? An unconditional synchronize_net() in ppp_unregister_channel() alone does not look sufficient. The other caller may not have run list_del_rcu() yet when that grace period starts.
Should the second ppp_disconnect_channel() caller wait for the first one to finish the list removal and the grace period? Or should the channel be unlinked from ppp->channels before pch->ppp is cleared, so that seeing NULL there implies it is already off the list?
[Severity: Low]
Should Documentation/networking/ppp_generic.rst be updated as well? pppoe is the first in-tree channel to set lockless_xmit, but the document still promises every channel:
The generic layer will not call the start_xmit() function for a channel while any thread is already executing in that function for that channel.
The document also says start_xmit() can return 0 for flow control, with the channel calling ppp_output_wakeup() later.
For a lockless_xmit channel, ppp_xmit_lockless() calls chan->ops->start_xmit() under rcu_read_lock() only, from several CPUs at once. It also treats a 0 return as a bug, with WARN_ON_ONCE() and kfree_skb().
The only description of the new contract is the comment on struct ppp_channel::lockless_xmit in include/linux/ppp_channel.h ("concurrent start_xmit, never 0"). No patch in the series touches Documentation/.
Quoted 3 lines
drivers/net/ppp/pppoe.c +0
-0error =ppp_register_net_channel (dev_net (dev), &po->chan);if (error) {
[ ... ]
drivers/net/ppp/pppoe.c static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb) · line 818
Quoted 6 lines
drivers/net/ppp/pppoe.c +1
-1@@ -814,7 +815,7 @@ static int pppoe_xmit(struct ppp_channel *chan, struct sk_buff *skb) {struct sock *sk = chan->private;struct pppox_sock *po =pppox_sk (sk); -struct net_device *dev = po->pppoe_dev; +struct net_device *dev =READ_ONCE (po->pppoe_dev);
[Severity: Low]
Should pppoe_fill_forward_path() use READ_ONCE() too? It still loads po->pppoe_dev without annotation. pppoe_release() and pppoe_unbind_sock_work() now clear that field with WRITE_ONCE():
drivers/net/ppp/pppoe.c:pppoe_fill_forward_path() {
struct sock *sk = chan->private;
struct pppox_sock *po = pppox_sk(sk);
struct net_device *dev = po->pppoe_dev;
if (sock_flag(sk, SOCK_DEAD) ||
!(sk->sk_state & PPPOX_CONNECTED) || !dev)
return -1;
...
ctx->dev = dev;
...
}pppoe_fill_forward_path() is called from ppp_fill_forward_path(). That function finds the channel with list_first_or_null_rcu() on ppp->channels and takes neither downl nor lock_sock().
This means it can run in pppoe_release() after WRITE_ONCE(po->pppoe_dev, NULL) and before pppox_unbind_sock(). KCSAN would still report that pair. In theory, the compiler could also reload the field between the NULL check and the use.
Quoted 3 lines
drivers/net/ppp/pppoe.c +0
-0struct pppoe_hdr *ph;int data_len = skb->len;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129144319.1489366-1-julius%40bairaktaris.de
PATCH 3/3 selftests: net: ppp: send on PPPoE from every CPU at once
In reply to Julius BairaktarisRun one iperf3 stream per CPU, each pinned with taskset, over the PPPoE session. Count the IPv4 and IPv6 session frames leaving the client's veth with flower filters and check that they match the frames and bytes ppp0 counted. A frame sent while the counters are read can be counted by only one of them, so they are read until two reads 100 ms apart agree. This covers concurrent use of the PPP transmit path and its per-CPU statistics.
--- tools/testing/selftests/net/ppp/config | 4 ++ tools/testing/selftests/net/ppp/pppoe.sh | 83 ++++++++++++++++++++++++ 2 files changed, 87 insertions(+)
tools/testing/selftests/net/ppp/config +4 -0
@@ -1,5 +1,9 @@ CONFIG_IPV6=y CONFIG_L2TP=m +CONFIG_NET_ACT_GACT=m +CONFIG_NET_CLS_ACT=y +CONFIG_NET_CLS_FLOWER=m +CONFIG_NET_SCH_INGRESS=m CONFIG_PACKET=y CONFIG_PPP=m CONFIG_PPP_ASYNC=m
tools/testing/selftests/net/ppp/pppoe.sh +83 -0
101 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 2 · Low: 2
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] ppp_test_parallel() sets ncpus=$(nproc), which is a count of the CPUs in the process's affinity mask, and then pins clients with…
- [Medium] In ppp_test_parallel(), the return codes of tc qdisc add ... clsact and `tc filter add ... protocol ppp_ses flower ppp_proto ...…
- [Low] The comment above client_tx_stats() in tools/testing/selftests/net/ppp/pppoe.sh says "PPP control frames go…
- [Low] The patch adds RET=0 before ppp_test_parallel, after log_test "PPPoE" has already used the connectivity result.
--
selftests: net: ppp: send on PPPoE from every CPU at once
This adds a PPPoE selftest that runs one iperf3 client per CPU, each pinned with taskset. It compares ppp0's transmit counters against flower filter counters for IPv4 and IPv6 session frames on the client veth, re-reading them until two reads 100 ms apart agree.
Quoted 4 lines
tools/testing/selftests/net/ppp/pppoe.sh +0
-0
[ ... ]
tools/testing/selftests/net/ppp/pppoe.sh ip link set "$VETH_CLIENT" netns "$NS_CLIENT" · line 41
Quoted 7 lines
tools/testing/selftests/net/ppp/pppoe.sh +3
-0@@ -34,6 +36,82 @@ ip link set "$VETH_CLIENT" netns "$NS_CLIENT" ip -netns "$NS_SERVER" link set "$VETH_SERVER" up ip -netns "$NS_CLIENT" link set "$VETH_CLIENT" up +# Print the client's ppp0 transmit counters, then those of the IPv4 and +# IPv6 PPPoE session frames leaving its veth. PPP control frames go to +# the channel directly and are counted by neither.
[Severity: Low]
Does this hold for NCP frames? LCP and authentication frames go out on the channel fd. Frames written to the unit fd take the counted transmit path:
drivers/net/ppp/ppp_generic.c:ppp_write() {
...
case INTERFACE:
ppp_xmit_process(PF_TO_PPP(pf), skb);
...
}Frames with proto >= 0x8000 skip ppp_xmit_lockless() and reach ppp_prepare_tx_skb(). That function counts every protocol on ppp0:
drivers/net/ppp/ppp_generic.c:ppp_prepare_tx_skb() {
...
dev_sw_netstats_tx_add(dev, 1, skb->len - PPP_PROTO_LEN);
...
}pppd writes IPCP (0x8021), IPv6CP (0x8057) and CCP (0x80fd) frames to the unit fd, so ppp0's tx_packets and tx_bytes include them. The flower filters in ppp_test_parallel() only match ppp_proto 0x0021 and 0x0057.
Suppose an NCP frame is sent between the before and after snapshots, for example during an NCP renegotiation or a late IPv6CP/CCP exchange. Would d[0] then differ from d[2], so the test reports "PPP and Ethernet packet counts differ" even though the kernel counted correctly?
This is unlikely in a steady-state session during the 3 second window. Either way, the comment describes a counting model that doesn't fully hold.
Quoted 11 lines
tools/testing/selftests/net/ppp/pppoe.sh +11
-0+client_tx_stats() { + local stat + + for stat in tx_packets tx_bytes; do + ip netns exec "$NS_CLIENT" \ + cat "/sys/class/net/ppp0/statistics/$stat" + done + tc -n "$NS_CLIENT" -s -j filter show dev "$VETH_CLIENT" egress | + jq '[.[].options.actions[0].stats // empty] | + (map(.packets) | add), (map(.bytes) | add)' +}
[ ... ]
tools/testing/selftests/net/ppp/pppoe.sh ip link set "$VETH_CLIENT" netns "$NS_CLIENT" · line 79
Quoted 9 lines
tools/testing/selftests/net/ppp/pppoe.sh +9
-0+ppp_test_parallel() { + local ncpus cpu i pids=() before after d=() proto + + # PPP protocol numbers of IPv4 and IPv6 + tc -n "$NS_CLIENT" qdisc add dev "$VETH_CLIENT" clsact + for proto in 0x0021 0x0057; do + tc -n "$NS_CLIENT" filter add dev "$VETH_CLIENT" egress \ + protocol ppp_ses flower ppp_proto "$proto" action pass + done
[Severity: Medium]
What happens if tc can't install these filters? The return codes of the qdisc and filter add commands aren't checked.
Nothing checks that the installed iproute2 supports flower's ppp_proto key, which is a recent addition. Nothing checks that cls_flower, act_gact and sch_ingress are available either.
Without the filters, the jq expression in client_tx_stats() prints null. If the filter show itself fails, it prints nothing. Bash arithmetic treats both as 0 in:
d[i]=$((after[i] - before[i]))
d[2] and d[3] end up as 0, and the test fails with "PPP and Ethernet packet counts differ" when it should skip for a missing feature.
Could the tc setup results be checked so that the test skips in this case?
Quoted 9 lines
tools/testing/selftests/net/ppp/pppoe.sh +9
-0+ + ncpus=$(nproc) + [ "$ncpus" -gt 8 ] && ncpus=8 + for ((cpu = 0; cpu < ncpus; cpu++)); do + ip netns exec "$NS_SERVER" iperf3 -s -1 -D -p $((5301 + cpu)) + wait_local_port_listen "$NS_SERVER" $((5301 + cpu)) tcp + done + + mapfile -t before < <(client_tx_stats_settled)
tools/testing/selftests/net/ppp/pppoe.sh ip link set "$VETH_CLIENT" netns "$NS_CLIENT" · line 98
Quoted 10 lines
tools/testing/selftests/net/ppp/pppoe.sh +10
-0+ for ((cpu = 0; cpu < ncpus; cpu++)); do + ip netns exec "$NS_CLIENT" taskset -c "$cpu" \ + iperf3 -c "$IP_SERVER" -p $((5301 + cpu)) -Z -t 3 \ + > /dev/null & + pids+=($!) + done + for i in "${pids[@]}"; do + wait "$i" + check_err $? "iperf3 client failed" + done
[Severity: Medium]
nproc returns how many CPUs are in the affinity mask, but these loops use that count as CPU IDs 0..ncpus-1. Can taskset fail when the allowed CPUs don't start at 0, or when there are gaps?
For example, under a cgroup cpuset of 4-7, nproc returns 4 and the loop runs taskset -c 0 through 3. __sched_setaffinity() ANDs the requested mask with cpuset_cpus_allowed(), which leaves an empty mask. The affinity call fails with EINVAL and taskset exits non-zero.
wait then returns non-zero, and check_err records "iperf3 client failed". The matching iperf3 -s -1 -D server is left listening. Offline CPUs can cause the same thing.
The subject and commit message say "from every CPU" and "one iperf3 stream per CPU". The count is silently capped at 8, though.
With nproc == 1 there is only one stream and no concurrency, but "PPPoE parallel transmit" still reports a pass. Should the test skip when fewer than 2 CPUs are available?
[ ... ]
tools/testing/selftests/net/ppp/pppoe.sh ppp_test_connectivity · line 140
Quoted 11 lines
tools/testing/selftests/net/ppp/pppoe.sh +5
-0@@ -53,6 +131,11 @@ ppp_test_connectivity log_test "PPPoE" +RET=0 +ppp_test_parallel + +log_test "PPPoE parallel transmit" + # Dump syslog messages if the test failed if [ "$RET" -ne 0 ]; then
[Severity: Low]
Does resetting RET lose the syslog dump when the connectivity test fails? log_test() in net/lib.sh merges RET into EXIT_STATUS and leaves RET as it was. Before this change, this check reflected the result of ppp_test_connectivity.
Now suppose ppp_test_connectivity fails and ppp_test_parallel passes. The run still fails through EXIT_STATUS, but this check is false, so the pppd/pppoe-server log is not printed.
pppol2tp.sh in the same directory has the same two-test structure and keys its dump on EXIT_STATUS. Could this check use EXIT_STATUS too?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261129144319.1489366-1-julius%40bairaktaris.de