* [PATCH net-next 1/3] ppp: transmit data frames without the unit and channel locks
2026-11-29 14:43 [PATCH net-next 0/3] ppp: transmit data frames without the unit and channel locks Julius Bairaktaris
@ 2026-11-29 14:43 ` Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once Julius Bairaktaris
2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-29 14:43 UTC (permalink / raw)
To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Simon Horman, Shuah Khan, Qingfang Deng,
Guillaume Nault, Sebastian Andrzej Siewior, Haoli Zhang,
linux-ppp, netdev, linux-kernel, linux-kselftest
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.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/ppp/ppp_generic.c | 85 ++++++++++++++++++++++++++++++++---
include/linux/ppp_channel.h | 1 +
2 files changed, 79 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
index bd5a7630f297..89a756ae3f4a 100644
--- a/drivers/net/ppp/ppp_generic.c
+++ b/drivers/net/ppp/ppp_generic.c
@@ -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 long
ppp_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;
diff --git a/include/linux/ppp_channel.h b/include/linux/ppp_channel.h
index 15bc3aa4f171..a0de060623a1 100644
--- a/include/linux/ppp_channel.h
+++ b/include/linux/ppp_channel.h
@@ -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__
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock
2026-11-29 14:43 [PATCH net-next 0/3] ppp: transmit data frames without the unit and channel locks Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 1/3] " Julius Bairaktaris
@ 2026-11-29 14:43 ` Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once Julius Bairaktaris
2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-29 14:43 UTC (permalink / raw)
To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Simon Horman, Shuah Khan, Qingfang Deng,
Guillaume Nault, Sebastian Andrzej Siewior, Haoli Zhang,
linux-ppp, netdev, linux-kernel, linux-kselftest
pppoe_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.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
drivers/net/ppp/pppoe.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ppp/pppoe.c b/drivers/net/ppp/pppoe.c
index de6edc31790f..f14ed72eb9d5 100644
--- a/drivers/net/ppp/pppoe.c
+++ b/drivers/net/ppp/pppoe.c
@@ -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;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next 3/3] selftests: net: ppp: send on PPPoE from every CPU at once
2026-11-29 14:43 [PATCH net-next 0/3] ppp: transmit data frames without the unit and channel locks Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 1/3] " Julius Bairaktaris
2026-11-29 14:43 ` [PATCH net-next 2/3] pppoe: transmit without the PPP channel lock Julius Bairaktaris
@ 2026-11-29 14:43 ` Julius Bairaktaris
2 siblings, 0 replies; 4+ messages in thread
From: Julius Bairaktaris @ 2026-11-29 14:43 UTC (permalink / raw)
To: Andrew Lunn, David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Willem de Bruijn, Simon Horman, Shuah Khan, Qingfang Deng,
Guillaume Nault, Sebastian Andrzej Siewior, Haoli Zhang,
linux-ppp, netdev, linux-kernel, linux-kselftest
Run 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.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
tools/testing/selftests/net/ppp/config | 4 ++
tools/testing/selftests/net/ppp/pppoe.sh | 83 ++++++++++++++++++++++++
2 files changed, 87 insertions(+)
diff --git a/tools/testing/selftests/net/ppp/config b/tools/testing/selftests/net/ppp/config
index 843545df8f03..e7ba52a36026 100644
--- a/tools/testing/selftests/net/ppp/config
+++ b/tools/testing/selftests/net/ppp/config
@@ -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
diff --git a/tools/testing/selftests/net/ppp/pppoe.sh b/tools/testing/selftests/net/ppp/pppoe.sh
index f67b51df7490..93c8dbb58818 100755
--- a/tools/testing/selftests/net/ppp/pppoe.sh
+++ b/tools/testing/selftests/net/ppp/pppoe.sh
@@ -17,6 +17,8 @@ cleanup() {
trap cleanup EXIT
require_command pppoe-server
+require_command taskset
+require_command jq
ppp_common_init
modprobe -q pppoe
@@ -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.
+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)'
+}
+
+# A frame sent while the counters are read can be counted by only one of
+# them. Read them until two reads 100 ms apart agree.
+client_tx_stats_settled() {
+ local prev cur i
+
+ prev=$(client_tx_stats)
+ for ((i = 0; i < 50; i++)); do
+ sleep 0.1
+ cur=$(client_tx_stats)
+ [ "$cur" = "$prev" ] && break
+ prev=$cur
+ done
+ echo "$cur"
+}
+
+# Send TCP streams from every CPU at once, then check that each frame
+# counted by the PPP device left the Ethernet device exactly once.
+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
+
+ 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)
+ 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
+ mapfile -t after < <(client_tx_stats_settled)
+
+ # 0-1: ppp0 packets and bytes; 2-3: the same on the veth
+ for i in 0 1 2 3; do
+ d[i]=$((after[i] - before[i]))
+ done
+ echo "ppp0: ${d[0]} packets, ${d[1]} bytes; veth: ${d[2]}, ${d[3]}"
+
+ [ "${d[0]}" -gt 0 ] && [ "${d[0]}" -eq "${d[2]}" ]
+ check_err $? "PPP and Ethernet packet counts differ"
+
+ # Ethernet (14), PPPoE (6) and PPP protocol (2) header per frame
+ [ "${d[3]}" -eq $((d[1] + 22 * d[0])) ]
+ check_err $? "PPP and Ethernet byte counts differ"
+}
+
# Start socat as syslog listener
socat -v -u UNIX-RECV:/dev/log OPEN:/dev/null > "$PPPOE_LOG" 2>&1 &
SOCAT_PID=$!
@@ -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
while read -r _sign _date _time len _from _to
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread